Plugin Directory

Changeset 3350006


Ignore:
Timestamp:
08/26/2025 01:39:08 AM (6 months ago)
Author:
tlloancy
Message:

ENSURE NO CHANGES IN BULK EDIT WHEN NOT WANTED EXPLICITELY AND THIS INCLUDESS SWITCH AND SELECT

Location:
bulk-content-toolkit
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • bulk-content-toolkit/tags/1.2.4/bulk-content-toolkit.php

    r3349789 r3350006  
    33Plugin Name: Bulk Content Toolkit
    44Description: A comprehensive toolkit for efficiently managing bulk actions on various types of content in WordPress, including posts, pages, and custom post types.
    5 Version: 1.2.3
     5Version: 1.2.4
    66Requires at least: 5.0
    77Tested up to: 6.8
     
    116116    }
    117117}
    118 function bulkedittoolkit_save_custom_bulk_edit($post_id) { // modification de masse via quick edit
     118function bulkedittoolkit_save_custom_bulk_edit($post_id) {
    119119    global $bulkedittoolkit_bulk_edit_settings;
    120 bulkedittoolkit_debug_log("Hook save_post_product called for post ID: $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    121 if (isset($_REQUEST['post'])) {
     120    bulkedittoolkit_debug_log("Hook save_post_product called for post ID: $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     121    if (isset($_REQUEST['post'])) {
    122122        bulkedittoolkit_debug_log("Posts in REQUEST: " . print_r($_REQUEST['post'], true), $GLOBALS["bulkedittoolkit_is_debug_active"]);
    123123    }
    124 //error_log("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
     124
    125125    // Vérifiez si c'est une autosave ou si le type de post ne correspond pas
    126126    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) {
     
    132132    }
    133133    $fields_names = bulkedittoolkit_get_bulk_edit_field_name(get_post_type($post_id));
     134
    134135    // Traitement de la modification en masse
    135136    bulkedittoolkit_debug_log("before");
    136137    if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'edit' && isset($_REQUEST['bulk_edit'])) {
    137                 bulkedittoolkit_debug_log("after");
    138             // Sanitize and validate the array of post IDs
    139     $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array();
    140     $posts_to_update = array_map('intval', $posts_to_update); // Convert all elements to integers
    141     $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings)
    142             foreach ($fields_names as $field_name => $field_details) {
    143                                 bulkedittoolkit_debug_log("loop");
    144                                 bulkedittoolkit_debug_log($field_name);
    145         // Vérifie si ce champ spécifique est soumis dans la requête
    146         $custom_field_key = 'custom_' . $field_name;
    147                 bulkedittoolkit_debug_log($custom_field_key);
    148         // Get the input type for the field
    149         $input_type = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type(get_post_type($post_id), $field_name);
    150         if (isset($_REQUEST[$custom_field_key])) {
    151             $value = sanitize_text_field($_REQUEST[$custom_field_key]); // 'yes' si coché, sinon la valeur soumise
    152             // Skip empty values for non-checkbox fields to respect "— Aucun changement —"
    153             if ($value === '' && $input_type !== 'checkbox') {
    154                 bulkedittoolkit_debug_log("Skipping empty value for non-checkbox field $field_name", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     138        bulkedittoolkit_debug_log("after");
     139        // Sanitize and validate the array of post IDs
     140        $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array();
     141        $posts_to_update = array_map('intval', $posts_to_update); // Convert all elements to integers
     142        $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings)
     143        foreach ($fields_names as $field_name => $custom_field_key) {
     144            bulkedittoolkit_debug_log("loop");
     145            bulkedittoolkit_debug_log($field_name);
     146            // Vérifie si ce champ spécifique est soumis dans la requête
     147            $change_field_key = 'change_custom_' . $field_name;
     148            $custom_field_key = 'custom_' . $field_name;
     149            bulkedittoolkit_debug_log($custom_field_key);
     150
     151            // Get the input type for the field
     152            $input_type = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type(get_post_type($post_id), $field_name);
     153
     154            // Check if the change selector is set to "No Change" for non-checkbox fields
     155            if ($input_type !== 'checkbox' && isset($_REQUEST[$change_field_key]) && $_REQUEST[$change_field_key] === '') {
     156                bulkedittoolkit_debug_log("Skipping field $field_name due to 'No Change' selection", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    155157                continue;
    156158            }
    157             // For checkboxes, treat empty value as false
    158             if ($value === '' && $input_type === 'checkbox') {
    159                 $value = false;
    160                 bulkedittoolkit_debug_log("Checkbox $field_name received empty value, setting to false", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    161             }
    162         } else {
    163             // Si la clé n'est pas définie, cela signifie que la checkbox est décochée
     159
     160            // Handle checkboxes specifically
    164161            if ($input_type === 'checkbox') {
    165                 $value = false; // ou false, selon ce que votre logique attend
    166                 bulkedittoolkit_debug_log("Checkbox $field_name not set, applying false", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     162                if (isset($_REQUEST[$custom_field_key])) {
     163                    $value = sanitize_text_field($_REQUEST[$custom_field_key]);
     164                    if ($value === 'indeterminate') {
     165                        bulkedittoolkit_debug_log("Checkbox $field_name is indeterminate, skipping", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     166                        continue;
     167                    }
     168                    $value = $value === 'yes' ? 'yes' : 'no';
     169                    bulkedittoolkit_debug_log("Checkbox $field_name set to $value", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     170                } else {
     171                    bulkedittoolkit_debug_log("Checkbox $field_name not set in request, skipping", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     172                    continue; // Skip if checkbox is not included (unlikely with name attribute kept)
     173                }
    167174            } else {
    168                 bulkedittoolkit_debug_log("Skipping non-checkbox field $field_name as it was not submitted", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    169                 continue;
    170             }
    171         }
     175                if (isset($_REQUEST[$custom_field_key])) {
     176                    $value = sanitize_text_field($_REQUEST[$custom_field_key]);
     177                    // Skip empty values for non-checkbox fields when "Change to" is selected
     178                    if ($value === '' && isset($_REQUEST[$change_field_key]) && $_REQUEST[$change_field_key] === '1') {
     179                        bulkedittoolkit_debug_log("Skipping empty value for non-checkbox field $field_name", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     180                        continue;
     181                    }
     182                } else {
     183                    bulkedittoolkit_debug_log("Skipping non-checkbox field $field_name as it was not submitted", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     184                    continue;
     185                }
     186            }
    172187            bulkedittoolkit_debug_log("Value for $field_name: $value", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    173188            foreach ($posts_to_update as $post_id) {
    174                 // Supposant que set_coming_soon peut gérer différents champs ou que vous avez une fonction plus générique
    175189                bulkedittoolkit_set_coming_soon($post_id, $field_name, $value);
    176190                bulkedittoolkit_debug_log("Bulk edit set $field_name to $value for post $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    177191            }
    178     }
    179         //}
     192        }
    180193        return; // Sortir après avoir traité la modification en masse
    181194    }
    182         if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {
    183     $post_id = intval($_REQUEST["post_ID"]); // Sanitize post ID
    184     if (get_post($post_id)) { // Check if the post exists
    185         bulkedittoolkit_save_custom_quick_edit($post_id);
    186     } else {
    187         bulkedittoolkit_debug_log("Post with ID $post_id does not exist.");
    188         // Optionally, you can redirect or send an error message here
    189         // wp_redirect(admin_url('edit.php?message=error'));
    190         // exit;
    191     }
    192 }
     195    if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {
     196        $post_id = intval($_REQUEST["post_ID"]);
     197        if (get_post($post_id)) {
     198            bulkedittoolkit_save_custom_quick_edit($post_id);
     199        } else {
     200            bulkedittoolkit_debug_log("Post with ID $post_id does not exist.");
     201        }
     202    }
    193203}
    194204function bulkedittoolkit_add_custom_columns($columns) {
  • bulk-content-toolkit/tags/1.2.4/js/user.js

    r3349789 r3350006  
    8989                                    bulkEditSwitch.indeterminate = true;
    9090                                    bulkEditSwitch.checked = false;
    91                                     bulkEditSwitch.removeAttribute('name');
     91                                    bulkEditSwitch.setAttribute('name', 'custom_' + fieldName);
     92                                    bulkEditSwitch.setAttribute('value', 'indeterminate');
    9293                                    bulkEditSwitch.setAttribute('data-indeterminate', 'true');
    9394                                    bulkEditSwitch.parentNode.classList.add('indeterminate');
  • bulk-content-toolkit/tags/1.2.4/readme.txt

    r3349789 r3350006  
    66Tested up to: 6.8
    77Requires PHP: 7.4
    8 Stable Tag: 1.2.3
     8Stable Tag: 1.2.4
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4646
    4747== Changelog ==
     48
     49= 1.2.4 =
     50- Fixed: Ensured "Aucun changement" (No Change) option for select fields in bulk edit correctly prevents unintended updates to fields.
     51- Attempt: Correct Select and Switches behavior in bulk edit mode by passing undetermined states into $_REQUEST instead of deleting names.
    4852
    4953= 1.2.3 =
  • bulk-content-toolkit/trunk/bulk-content-toolkit.php

    r3349789 r3350006  
    33Plugin Name: Bulk Content Toolkit
    44Description: A comprehensive toolkit for efficiently managing bulk actions on various types of content in WordPress, including posts, pages, and custom post types.
    5 Version: 1.2.3
     5Version: 1.2.4
    66Requires at least: 5.0
    77Tested up to: 6.8
     
    116116    }
    117117}
    118 function bulkedittoolkit_save_custom_bulk_edit($post_id) { // modification de masse via quick edit
     118function bulkedittoolkit_save_custom_bulk_edit($post_id) {
    119119    global $bulkedittoolkit_bulk_edit_settings;
    120 bulkedittoolkit_debug_log("Hook save_post_product called for post ID: $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    121 if (isset($_REQUEST['post'])) {
     120    bulkedittoolkit_debug_log("Hook save_post_product called for post ID: $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     121    if (isset($_REQUEST['post'])) {
    122122        bulkedittoolkit_debug_log("Posts in REQUEST: " . print_r($_REQUEST['post'], true), $GLOBALS["bulkedittoolkit_is_debug_active"]);
    123123    }
    124 //error_log("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
     124
    125125    // Vérifiez si c'est une autosave ou si le type de post ne correspond pas
    126126    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) {
     
    132132    }
    133133    $fields_names = bulkedittoolkit_get_bulk_edit_field_name(get_post_type($post_id));
     134
    134135    // Traitement de la modification en masse
    135136    bulkedittoolkit_debug_log("before");
    136137    if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'edit' && isset($_REQUEST['bulk_edit'])) {
    137                 bulkedittoolkit_debug_log("after");
    138             // Sanitize and validate the array of post IDs
    139     $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array();
    140     $posts_to_update = array_map('intval', $posts_to_update); // Convert all elements to integers
    141     $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings)
    142             foreach ($fields_names as $field_name => $field_details) {
    143                                 bulkedittoolkit_debug_log("loop");
    144                                 bulkedittoolkit_debug_log($field_name);
    145         // Vérifie si ce champ spécifique est soumis dans la requête
    146         $custom_field_key = 'custom_' . $field_name;
    147                 bulkedittoolkit_debug_log($custom_field_key);
    148         // Get the input type for the field
    149         $input_type = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type(get_post_type($post_id), $field_name);
    150         if (isset($_REQUEST[$custom_field_key])) {
    151             $value = sanitize_text_field($_REQUEST[$custom_field_key]); // 'yes' si coché, sinon la valeur soumise
    152             // Skip empty values for non-checkbox fields to respect "— Aucun changement —"
    153             if ($value === '' && $input_type !== 'checkbox') {
    154                 bulkedittoolkit_debug_log("Skipping empty value for non-checkbox field $field_name", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     138        bulkedittoolkit_debug_log("after");
     139        // Sanitize and validate the array of post IDs
     140        $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array();
     141        $posts_to_update = array_map('intval', $posts_to_update); // Convert all elements to integers
     142        $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings)
     143        foreach ($fields_names as $field_name => $custom_field_key) {
     144            bulkedittoolkit_debug_log("loop");
     145            bulkedittoolkit_debug_log($field_name);
     146            // Vérifie si ce champ spécifique est soumis dans la requête
     147            $change_field_key = 'change_custom_' . $field_name;
     148            $custom_field_key = 'custom_' . $field_name;
     149            bulkedittoolkit_debug_log($custom_field_key);
     150
     151            // Get the input type for the field
     152            $input_type = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type(get_post_type($post_id), $field_name);
     153
     154            // Check if the change selector is set to "No Change" for non-checkbox fields
     155            if ($input_type !== 'checkbox' && isset($_REQUEST[$change_field_key]) && $_REQUEST[$change_field_key] === '') {
     156                bulkedittoolkit_debug_log("Skipping field $field_name due to 'No Change' selection", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    155157                continue;
    156158            }
    157             // For checkboxes, treat empty value as false
    158             if ($value === '' && $input_type === 'checkbox') {
    159                 $value = false;
    160                 bulkedittoolkit_debug_log("Checkbox $field_name received empty value, setting to false", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    161             }
    162         } else {
    163             // Si la clé n'est pas définie, cela signifie que la checkbox est décochée
     159
     160            // Handle checkboxes specifically
    164161            if ($input_type === 'checkbox') {
    165                 $value = false; // ou false, selon ce que votre logique attend
    166                 bulkedittoolkit_debug_log("Checkbox $field_name not set, applying false", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     162                if (isset($_REQUEST[$custom_field_key])) {
     163                    $value = sanitize_text_field($_REQUEST[$custom_field_key]);
     164                    if ($value === 'indeterminate') {
     165                        bulkedittoolkit_debug_log("Checkbox $field_name is indeterminate, skipping", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     166                        continue;
     167                    }
     168                    $value = $value === 'yes' ? 'yes' : 'no';
     169                    bulkedittoolkit_debug_log("Checkbox $field_name set to $value", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     170                } else {
     171                    bulkedittoolkit_debug_log("Checkbox $field_name not set in request, skipping", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     172                    continue; // Skip if checkbox is not included (unlikely with name attribute kept)
     173                }
    167174            } else {
    168                 bulkedittoolkit_debug_log("Skipping non-checkbox field $field_name as it was not submitted", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    169                 continue;
    170             }
    171         }
     175                if (isset($_REQUEST[$custom_field_key])) {
     176                    $value = sanitize_text_field($_REQUEST[$custom_field_key]);
     177                    // Skip empty values for non-checkbox fields when "Change to" is selected
     178                    if ($value === '' && isset($_REQUEST[$change_field_key]) && $_REQUEST[$change_field_key] === '1') {
     179                        bulkedittoolkit_debug_log("Skipping empty value for non-checkbox field $field_name", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     180                        continue;
     181                    }
     182                } else {
     183                    bulkedittoolkit_debug_log("Skipping non-checkbox field $field_name as it was not submitted", $GLOBALS["bulkedittoolkit_is_debug_active"]);
     184                    continue;
     185                }
     186            }
    172187            bulkedittoolkit_debug_log("Value for $field_name: $value", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    173188            foreach ($posts_to_update as $post_id) {
    174                 // Supposant que set_coming_soon peut gérer différents champs ou que vous avez une fonction plus générique
    175189                bulkedittoolkit_set_coming_soon($post_id, $field_name, $value);
    176190                bulkedittoolkit_debug_log("Bulk edit set $field_name to $value for post $post_id", $GLOBALS["bulkedittoolkit_is_debug_active"]);
    177191            }
    178     }
    179         //}
     192        }
    180193        return; // Sortir après avoir traité la modification en masse
    181194    }
    182         if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {
    183     $post_id = intval($_REQUEST["post_ID"]); // Sanitize post ID
    184     if (get_post($post_id)) { // Check if the post exists
    185         bulkedittoolkit_save_custom_quick_edit($post_id);
    186     } else {
    187         bulkedittoolkit_debug_log("Post with ID $post_id does not exist.");
    188         // Optionally, you can redirect or send an error message here
    189         // wp_redirect(admin_url('edit.php?message=error'));
    190         // exit;
    191     }
    192 }
     195    if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {
     196        $post_id = intval($_REQUEST["post_ID"]);
     197        if (get_post($post_id)) {
     198            bulkedittoolkit_save_custom_quick_edit($post_id);
     199        } else {
     200            bulkedittoolkit_debug_log("Post with ID $post_id does not exist.");
     201        }
     202    }
    193203}
    194204function bulkedittoolkit_add_custom_columns($columns) {
  • bulk-content-toolkit/trunk/js/user.js

    r3349789 r3350006  
    8989                                    bulkEditSwitch.indeterminate = true;
    9090                                    bulkEditSwitch.checked = false;
    91                                     bulkEditSwitch.removeAttribute('name');
     91                                    bulkEditSwitch.setAttribute('name', 'custom_' + fieldName);
     92                                    bulkEditSwitch.setAttribute('value', 'indeterminate');
    9293                                    bulkEditSwitch.setAttribute('data-indeterminate', 'true');
    9394                                    bulkEditSwitch.parentNode.classList.add('indeterminate');
  • bulk-content-toolkit/trunk/readme.txt

    r3349789 r3350006  
    66Tested up to: 6.8
    77Requires PHP: 7.4
    8 Stable Tag: 1.2.3
     8Stable Tag: 1.2.4
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4646
    4747== Changelog ==
     48
     49= 1.2.4 =
     50- Fixed: Ensured "Aucun changement" (No Change) option for select fields in bulk edit correctly prevents unintended updates to fields.
     51- Attempt: Correct Select and Switches behavior in bulk edit mode by passing undetermined states into $_REQUEST instead of deleting names.
    4852
    4953= 1.2.3 =
Note: See TracChangeset for help on using the changeset viewer.