Changeset 3349434
- Timestamp:
- 08/25/2025 04:36:56 AM (6 months ago)
- Location:
- bulk-content-toolkit
- Files:
-
- 16 edited
- 1 copied
-
tags/1.2.2 (copied) (copied from bulk-content-toolkit/trunk)
-
tags/1.2.2/bulk-content-toolkit.php (modified) (14 diffs)
-
tags/1.2.2/includes/admin/bulk-actions.php (modified) (4 diffs)
-
tags/1.2.2/includes/admin/quick-edit.php (modified) (15 diffs)
-
tags/1.2.2/includes/core-functions.php (modified) (1 diff)
-
tags/1.2.2/includes/utils/helpers.php (modified) (1 diff)
-
tags/1.2.2/js/bulk-edit-admin.js (modified) (4 diffs)
-
tags/1.2.2/js/user.js (modified) (6 diffs)
-
tags/1.2.2/readme.txt (modified) (2 diffs)
-
trunk/bulk-content-toolkit.php (modified) (14 diffs)
-
trunk/includes/admin/bulk-actions.php (modified) (4 diffs)
-
trunk/includes/admin/quick-edit.php (modified) (15 diffs)
-
trunk/includes/core-functions.php (modified) (1 diff)
-
trunk/includes/utils/helpers.php (modified) (1 diff)
-
trunk/js/bulk-edit-admin.js (modified) (4 diffs)
-
trunk/js/user.js (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bulk-content-toolkit/tags/1.2.2/bulk-content-toolkit.php
r3349072 r3349434 3 3 Plugin Name: Bulk Content Toolkit 4 4 Description: 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. 15 Version: 1.2.2 6 6 Requires at least: 5.0 7 7 Tested up to: 6.8 … … 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html 14 14 */ 15 16 15 defined('ABSPATH') or die('No script kiddies please!'); 17 18 16 // Initialisation de la classe avant les includes 19 17 require_once plugin_dir_path(__FILE__) . 'includes/classes/BulkEditSettings.php'; … … 27 25 require_once plugin_dir_path(__FILE__) . 'includes/api/ajax-handlers.php'; 28 26 require_once plugin_dir_path(__FILE__) . 'includes/utils/helpers.php'; 29 30 27 // Hook pour la fonction d'activation 31 28 register_activation_hook(__FILE__, 'bulkedittoolkit_bulk_edit_plugin_activate'); 32 33 29 function bulkedittoolkit_bulk_edit_plugin_activate() { 34 30 global $wpdb; 35 36 31 $table_name = $wpdb->prefix . 'bulkedittoolkit_plugin_bulk_edit_settings'; 37 38 32 $charset_collate = $wpdb->get_charset_collate(); 39 40 33 $sql = "CREATE TABLE $table_name ( 41 34 id INT(11) UNSIGNED AUTO_INCREMENT, … … 43 36 field_name VARCHAR(255) NOT NULL, 44 37 input_type ENUM( 45 'text', 'password', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 46 'number', 'email', 'url', 'search', 'tel', 'color', 38 'text', 'password', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 39 'number', 'email', 'url', 'search', 'tel', 'color', 47 40 'checkbox', 'radio', 'file', 'hidden', 'image', 'button', 'reset', 'submit', 48 41 'range', 'textarea', 'select', 'label', 'fieldset', 'legend', 49 42 'json', 'editor', 'slider', 'toggle', 'datepicker', 'timepicker' 50 43 ) NOT NULL, 51 PRIMARY KEY (id),44 PRIMARY KEY (id), 52 45 UNIQUE KEY unique_post_type_field_name (post_type, field_name) 53 46 ) $charset_collate;"; 54 55 47 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 56 48 dbDelta($sql); 57 58 49 add_option('bulkedittoolkit_bulk_edit_plugin_version', '1.0'); 59 50 } 60 61 51 register_deactivation_hook(__FILE__, 'bulkedittoolkit_bulk_edit_plugin_deactivate'); 62 63 52 function bulkedittoolkit_bulk_edit_plugin_deactivate() { 64 53 add_action('admin_notices', 'bulkedittoolkit_bulk_edit_deactivation_warning'); 65 // Ajoutez ici la logique pour vérifier si le plugin est en cours de désactivation66 54 if (isset($_POST['confirm_delete_bulk_settings']) || isset($_POST['cancel_delete_bulk_settings'])) { 67 if (wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { 68 bulkedittoolkit_bulk_edit_handle_deactivation_form(); 69 } 70 } 71 } 72 55 if (wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { 56 bulkedittoolkit_bulk_edit_handle_deactivation_form(); 57 } 58 } 59 } 73 60 function bulkedittoolkit_bulk_edit_deactivation_warning() { 74 $nonce = wp_create_nonce('bulk_edit_settings_nonce');61 $nonce = wp_create_nonce('bulk_edit_settings_nonce'); 75 62 ?> 76 63 <div class="notice notice-warning is-dismissible"> 77 64 <p><?php esc_html_e('Attention : Si vous désactivez ce plugin, vous pouvez perdre les paramètres de masse enregistrés. Voulez-vous vraiment supprimer les données de Bulk Edit ?', 'bulk-content-toolkit'); ?></p> 78 65 <form method="post" action=""> 79 <?php wp_nonce_field('bulk_edit_settings_nonce'); ?>66 <?php wp_nonce_field('bulk_edit_settings_nonce'); ?> 80 67 <input type="submit" name="confirm_delete_bulk_settings" class="button button-primary" value="<?php esc_attr_e('Confirmer la suppression', 'bulk-content-toolkit'); ?>"> 81 68 <input type="submit" name="cancel_delete_bulk_settings" class="button" value="<?php esc_attr_e('Annuler', 'bulk-content-toolkit'); ?>"> … … 84 71 <?php 85 72 } 86 87 73 function bulkedittoolkit_bulk_edit_handle_deactivation_form() { 88 74 if (isset($_POST['confirm_delete_bulk_settings']) && wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { … … 93 79 } 94 80 } 95 96 81 function bulkedittoolkit_bulk_edit_delete_table() { 97 82 global $wpdb; … … 99 84 $wpdb->query("DROP TABLE IF EXISTS $table_name"); 100 85 delete_option('bulkedittoolkit_bulk_edit_plugin_version'); 101 102 86 wp_redirect(admin_url('plugins.php?deactivate=true')); 103 87 exit; 104 88 } 105 106 // Initialize the settings if they don't exist107 /*initialize_bulk_edit_settings();108 109 */110 89 function bulkedittoolkit_setup_post_type_specific_actions() { 111 90 $bulkedittoolkit_bulkEditSettings = bulkedittoolkit_BulkEditSettings::get_instance(); 112 91 $post_types = $bulkedittoolkit_bulkEditSettings->bulkedittoolkit_get_all_post_types(); 113 92 foreach ($post_types as $post_type) { 114 // quick edit115 93 add_action('save_post_' . $post_type, 'bulkedittoolkit_save_custom_bulk_edit'); 116 //add_action('save_post_' . $post_type, 'save_custom_quick_edit'); 117 // bulk actions 118 add_filter('bulk_actions-edit-' . $post_type, 'bulkedittoolkit_add_custom_bulk_actions'); 119 add_filter('handle_bulk_actions-edit-' . $post_type, 'bulkedittoolkit_handle_custom_bulk_action', 10, 3); 120 } 121 } 122 94 add_filter('bulk_actions-edit-' . $post_type, 'bulkedittoolkit_add_custom_bulk_actions'); 95 add_filter('handle_bulk_actions-edit-' . $post_type, 'bulkedittoolkit_handle_custom_bulk_action', 10, 3); 96 } 97 } 123 98 add_action('init', 'bulkedittoolkit_setup_post_type_specific_actions'); 124 // Mapping for field functions, might be moved or used in a different way125 // D'abord, vérifions s'il y a un post spécifique pour obtenir le post_type126 99 function bulkedittoolkit_get_current_post_type() { 127 100 global $post; 128 global $bulkedittoolkit_current_post_type; 129 101 global $bulkedittoolkit_current_post_type; 130 102 if (isset($post) && is_object($post)) { 131 103 return get_post_type($post->ID); 132 104 } 133 134 // Si $post n'est pas défini, peut-être qu'on est dans une situation où on peut obtenir le post_type d'une autre manière,135 // comme par la query string ou via l'URL.136 105 $post_type = filter_input(INPUT_GET, 'post_type', FILTER_UNSAFE_RAW); 137 106 if ($post_type) { 138 107 return $post_type; 139 108 } 140 141 // En dernier recours, on pourrait définir un type de post par défaut ou retourner null/false pour gérer différemment. 142 return 'post'; // ou return null; selon ce qui convient le mieux à votre logique. 143 } 144 145 // Ensuite, initialiser $field_function_map basé sur le post_type actuel pourrait être fait ici, 146 // mais dans votre cas, vous avez déjà une logique pour initialiser $field_function_map. 147 // Initialisation de la classe des paramètres de bulk edit 148 109 return 'post'; 110 } 149 111 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 150 151 112 $bulkedittoolkit_field_function_map = []; 152 153 113 foreach ($settings as $post_type => $fields) { 154 114 foreach ($fields as $field) { 155 // Chaque champ, peu importe son nom, pointera vers 'set_coming_soon'156 115 $bulkedittoolkit_field_function_map[$field['field_name']] = 'bulkedittoolkit_set_coming_soon'; 157 116 } 158 117 } 159 160 // Debug pour vérifier le contenu du $field_function_map161 // var_dump($field_function_map); // Décommentez pour le debuggage162 163 // Si vous voulez ajuster votre map basé sur le post_type, vous pourriez faire quelque chose comme :164 /*$base_field_function_map = [165 'coming_soon' => 'set_coming_soon',166 ];*/167 /*168 // Vous pouvez dynamiquement ajouter des entrées basées sur la base de données pour éviter la duplication manuelle169 170 // Récupérer toutes les settings pour les intégrer dans le mapping171 $bulk_edit_settings = BulkEditSettings::get_instance();172 $settings = $bulk_edit_settings->get_settings();173 174 foreach ($settings as $post_type => $fields) {175 foreach ($fields as $field) {176 // Vérifiez si le field_name n'est pas déjà dans le map pour éviter les doublons177 if (!isset($field_function_map[$field['field_name']])) {178 // Ici, vous pourriez créer une logique pour générer automatiquement des noms de fonctions179 // ou utiliser une fonction par défaut si aucune correspondance n'est définie180 $field_function_map[$field['field_name']] = 'set_' . sanitize_key($field['field_name']);181 }182 }183 }184 185 // $field_function_map contient maintenant des entrées basées sur la DB et votre mapping initial*/186 187 // Cette structure dépend de comment vous gérez les différents post_types.188 /*$field_function_map = $base_field_function_map;189 190 // Si vous avez des mappings spécifiques pour certains post_types:191 $post_type_specific_map = [192 'lp_course' => [193 'course_open' => 'set_course_open_status',194 ],195 // Ajoutez d'autres post_types ici.196 ];197 198 if (isset($post_type_specific_map[$current_post_type])) {199 $field_function_map = array_merge($field_function_map, $post_type_specific_map[$current_post_type]);200 }201 */202 // Maintenant $field_function_map a les mappings généraux plus ceux spécifiques au post_type courant.203 204 /*205 // This function would initialize the settings if none exist206 function initialize_bulk_edit_settings() {207 if (false == get_option('bulk_edit_settings')) {208 add_option('bulk_edit_settings', [209 'post_type' => 'lp_course',210 'field_name' => 'coming_soon',211 'input_type' => 'checkbox',212 ]);213 }214 debug_log("Bulk edit settings initialized or already present", $GLOBALS["is_debug_active"]);215 }216 217 $bulk_edit_settings = get_option('bulk_edit_settings', [218 'post_type' => 'lp_course',219 'field_name' => 'coming_soon',220 'input_type' => 'checkbox'221 ]);222 */223 224 118 function bulkedittoolkit_save_custom_bulk_edit($post_id) { // modification de masse via quick edit 225 119 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'])) { 122 bulkedittoolkit_debug_log("Posts in REQUEST: " . print_r($_REQUEST['post'], true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 123 } 226 124 //error_log("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); 227 125 // Vérifiez si c'est une autosave ou si le type de post ne correspond pas … … 229 127 return; 230 128 } 231 232 129 $all_post_types = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_all_post_types(); 233 234 130 if (!in_array(get_post_type($post_id), $all_post_types)) { 235 131 return; // Sortir si le type de post actuel n'est pas dans la liste des types de posts gérés 236 132 } 237 238 133 $fields_names = bulkedittoolkit_get_bulk_edit_field_name(get_post_type($post_id)); 239 240 134 // Traitement de la modification en masse 241 135 bulkedittoolkit_debug_log("before"); 242 136 if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'edit' && isset($_REQUEST['bulk_edit'])) { 243 bulkedittoolkit_debug_log("after");137 bulkedittoolkit_debug_log("after"); 244 138 // Sanitize and validate the array of post IDs 245 139 $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array(); … … 247 141 $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings) 248 142 foreach ($fields_names as $field_name => $field_details) { 249 bulkedittoolkit_debug_log("loop");250 bulkedittoolkit_debug_log($field_name);143 bulkedittoolkit_debug_log("loop"); 144 bulkedittoolkit_debug_log($field_name); 251 145 // Vérifie si ce champ spécifique est soumis dans la requête 252 146 $custom_field_key = 'custom_' . $field_name; 253 bulkedittoolkit_debug_log($custom_field_key); 254 if (isset($_REQUEST[$custom_field_key])) { 255 $value = sanitize_text_field($_REQUEST[$custom_field_key]); // 'yes' si coché, sinon la valeur soumise 256 } else { 257 // Si la clé n'est pas définie, cela signifie que la checkbox est décochée 258 $value = false; // ou false, selon ce que votre logique attend 259 } 260 261 bulkedittoolkit_debug_log($value); 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"]); 155 continue; 156 } 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 164 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"]); 167 } 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 } 172 bulkedittoolkit_debug_log("Value for $field_name: $value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 262 173 foreach ($posts_to_update as $post_id) { 263 174 // Supposant que set_coming_soon peut gérer différents champs ou que vous avez une fonction plus générique … … 269 180 return; // Sortir après avoir traité la modification en masse 270 181 } 271 if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {182 if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) { 272 183 $post_id = intval($_REQUEST["post_ID"]); // Sanitize post ID 273 274 184 if (get_post($post_id)) { // Check if the post exists 275 185 bulkedittoolkit_save_custom_quick_edit($post_id); … … 281 191 } 282 192 } 283 284 285 } 286 287 // Assurez-vous de hooker la fonction correctement 288 //debug_log($current_post_type);debug_log("TTTTTTTTTTTTTTTTTTTTTTT"); 289 //add_action('save_post_' . $current_post_type, 'save_custom_bulk_edit'); 290 291 292 293 294 295 296 // Add custom column 193 } 297 194 function bulkedittoolkit_add_custom_columns($columns) { 298 195 global $bulkedittoolkit_bulk_edit_settings; 299 global $bulkedittoolkit_current_post_type;300 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); // Supposons que get_settings() retourne tous les settings pour le post_type actuel196 global $bulkedittoolkit_current_post_type; 197 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 301 198 if (isset($settings[$bulkedittoolkit_current_post_type])) { 302 199 foreach($settings[$bulkedittoolkit_current_post_type] as $setting) { 303 $columns[$setting['field_name']] = ucfirst(implode(' ', explode('_', $setting['field_name']))); // human readable mon q304 bulkedittoolkit_debug_log(" Added custom column: " . $setting['field_name'], $GLOBALS["bulkedittoolkit_is_debug_active"]);200 $columns[$setting['field_name']] = ucfirst(implode(' ', explode('_', $setting['field_name']))); 201 bulkedittoolkit_debug_log("GROKTRACE_ADD_COLUMN: Added custom column: " . $setting['field_name'], $GLOBALS["bulkedittoolkit_is_debug_active"]); 305 202 } 306 203 } … … 308 205 } 309 206 add_filter('manage_' . $bulkedittoolkit_current_post_type . '_posts_columns', 'bulkedittoolkit_add_custom_columns'); 310 311 // Display custom column data312 207 function bulkedittoolkit_display_custom_column_data($column, $post_id) { 313 208 global $bulkedittoolkit_bulk_edit_settings; 314 global $bulkedittoolkit_current_post_type; 315 316 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); // Récupérer tous les settings 209 global $bulkedittoolkit_current_post_type; 210 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 317 211 if (isset($settings[$bulkedittoolkit_current_post_type])) { 318 212 foreach($settings[$bulkedittoolkit_current_post_type] as $setting) { 319 213 if ($column == $setting['field_name']) { 320 $meta_key = /*$current_post_type . '_' .*/$setting['field_name'];214 $meta_key = $setting['field_name']; 321 215 $status = get_post_meta($post_id, $meta_key, true); 322 323 // Affichage basé sur le type de l'input324 216 switch ($setting['input_type']) { 325 217 case 'checkbox': 326 echo $status && (strtolower($status) !== 'no' && strtolower($status) !== 0 && strtolower($status) !== false) ? 'Yes' : 'No'; // Pour les checkbox, on reste avec Yes/No218 echo $status && (strtolower($status) !== 'no' && strtolower($status) !== '0' && strtolower($status) !== 'false') ? 'Yes' : 'No'; 327 219 break; 328 220 case 'datetime': … … 331 223 break; 332 224 default: 333 echo esc_html($status); // Pour les autres types, afficher la valeur telle quelle, après échappement pour la sécurité225 echo esc_html($status); 334 226 } 335 336 bulkedittoolkit_debug_log("Displaying column data $post_id for $column with status: " . var_export($status, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 337 break; 338 bulkedittoolkit_debug_log("Displaying column data for $column with status: $status", $GLOBALS["bulkedittoolkit_is_debug_active"]); 339 break; // On sort de la boucle car on a trouvé notre colonne 227 bulkedittoolkit_debug_log("GROKTRACE_DISPLAY_COLUMN: Displaying column data $post_id for $column with status: " . var_export($status, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 340 228 } 341 229 } … … 343 231 } 344 232 add_action('manage_' . $bulkedittoolkit_current_post_type . '_posts_custom_column', 'bulkedittoolkit_display_custom_column_data', 10, 2); 345 346 347 348 // Here you would close your PHP file if there's no more code to add349 350 233 ?> -
bulk-content-toolkit/tags/1.2.2/includes/admin/bulk-actions.php
r3188505 r3349434 6 6 global $bulkedittoolkit_bulk_edit_settings; 7 7 8 $bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); // Obtenir le type de post courant ou utiliser un moyen approprié pour le définir8 /*$bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); // Obtenir le type de post courant ou utiliser un moyen approprié pour le définir 9 9 10 10 if ($bulkedittoolkit_current_post_type) { 11 11 $fields = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_field_names_for_post_type($bulkedittoolkit_current_post_type); 12 12 13 13 foreach ($fields as $field_name) { 14 14 $action_name = bulkedittoolkit_get_coming_soon_action_name($field_name); // Assurez-vous que cette fonction existe pour formater le nom de l'action … … 16 16 bulkedittoolkit_debug_log("Added bulk action for field: " . $field_name, $GLOBALS["bulkedittoolkit_is_debug_active"]); 17 17 } 18 } 18 }*/ 19 19 20 20 return $bulk_actions; … … 27 27 function bulkedittoolkit_handle_custom_bulk_action($redirect_to, $doaction, $post_ids) { //select set coming soon on the left 28 28 global $bulkedittoolkit_bulk_edit_settings; 29 29 30 30 $bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); 31 31 32 32 if ($bulkedittoolkit_current_post_type) { 33 33 $fields = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_field_names_for_post_type($bulkedittoolkit_current_post_type); … … 50 50 if (!empty($_REQUEST['bulk_' . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name') . '_items'])) { 51 51 $count = intval($_REQUEST['bulk_' . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name') . '_items']); 52 printf('<div id="message" class="updated notice is-dismissible"><p>' . 53 esc_html( _n('%s item has been set to %s.', '%s items have been set to %s.', $count, 'bulk-content-toolkit') ) . 52 printf('<div id="message" class="updated notice is-dismissible"><p>' . 53 esc_html( _n('%s item has been set to %s.', '%s items have been set to %s.', $count, 'bulk-content-toolkit') ) . 54 54 '</p></div>', $count, esc_html( ucfirst($bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name')) ) ); 55 55 bulkedittoolkit_debug_log("$count items processed for setting: " . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name'), $GLOBALS["bulkedittoolkit_is_debug_active"]); -
bulk-content-toolkit/tags/1.2.2/includes/admin/quick-edit.php
r3349071 r3349434 1 1 <?php 2 3 2 defined('ABSPATH') or die('PIF PAF POUF!'); 4 3 … … 15 14 global $bulkedittoolkit_bulk_edit_settings, $bulkedittoolkit_current_post_type; 16 15 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting($bulkedittoolkit_current_post_type); 17 if (!isset($settings)) return; // acs des onglets catégorie - étiquette16 if (!isset($settings)) return; // acs des onglets catégorie - étiquette 18 17 $settings = array_column($settings, 'input_type', 'field_name'); 19 20 18 $html_generators = [ 21 19 'checkbox' => function($field_name, $context = '') { 22 return bulkedittoolkit_generate_switch_html($field_name, $context);23 },24 'switch' => function($field_name, $context = '') {25 return bulkedittoolkit_generate_switch_html($field_name, $context);26 },27 'select' => function($field_name, $context = '') {28 return bulkedittoolkit_generate_select_html($field_name, $context);29 },30 'text' => function($field_name, $context = '') {31 return bulkedittoolkit_generate_text_html($field_name, $context);32 },33 'number' => function($field_name, $context = '') {34 return bulkedittoolkit_generate_number_html($field_name, $context);35 },36 'datetime' => function($field_name, $context = '') {37 return bulkedittoolkit_generate_datetime_html($field_name, $context);38 },39 'radio' => function($field_name, $context = '') {40 return bulkedittoolkit_generate_radio_html($field_name, $context);41 },42 'textarea' => function($field_name, $context = '') {43 return bulkedittoolkit_generate_textarea_html($field_name, $context);44 },45 'file' => function($field_name, $context = '') {46 return bulkedittoolkit_generate_file_html($field_name, $context);47 },48 'email' => function($field_name, $context = '') {49 return bulkedittoolkit_generate_email_html($field_name, $context);50 },51 'password' => function($field_name, $context = '') {52 return bulkedittoolkit_generate_password_html($field_name, $context);53 },54 'url' => function($field_name, $context = '') {55 return bulkedittoolkit_generate_url_html($field_name, $context);56 },57 'color' => function($field_name, $context = '') {58 return bulkedittoolkit_generate_color_html($field_name, $context);59 },60 'range' => function($field_name, $context = '') {61 return bulkedittoolkit_generate_range_html($field_name, $context);62 },20 return bulkedittoolkit_generate_switch_html($field_name, $context); 21 }, 22 'switch' => function($field_name, $context = '') { 23 return bulkedittoolkit_generate_switch_html($field_name, $context); 24 }, 25 'select' => function($field_name, $context = '') { 26 return bulkedittoolkit_generate_select_html($field_name, $context); 27 }, 28 'text' => function($field_name, $context = '') { 29 return bulkedittoolkit_generate_text_html($field_name, $context); 30 }, 31 'number' => function($field_name, $context = '') { 32 return bulkedittoolkit_generate_number_html($field_name, $context); 33 }, 34 'datetime' => function($field_name, $context = '') { 35 return bulkedittoolkit_generate_datetime_html($field_name, $context); 36 }, 37 'radio' => function($field_name, $context = '') { 38 return bulkedittoolkit_generate_radio_html($field_name, $context); 39 }, 40 'textarea' => function($field_name, $context = '') { 41 return bulkedittoolkit_generate_textarea_html($field_name, $context); 42 }, 43 'file' => function($field_name, $context = '') { 44 return bulkedittoolkit_generate_file_html($field_name, $context); 45 }, 46 'email' => function($field_name, $context = '') { 47 return bulkedittoolkit_generate_email_html($field_name, $context); 48 }, 49 'password' => function($field_name, $context = '') { 50 return bulkedittoolkit_generate_password_html($field_name, $context); 51 }, 52 'url' => function($field_name, $context = '') { 53 return bulkedittoolkit_generate_url_html($field_name, $context); 54 }, 55 'color' => function($field_name, $context = '') { 56 return bulkedittoolkit_generate_color_html($field_name, $context); 57 }, 58 'range' => function($field_name, $context = '') { 59 return bulkedittoolkit_generate_range_html($field_name, $context); 60 }, 63 61 ]; 64 65 62 if (!isset($settings[$post_type])) return; 66 67 $allowed_html = array( 63 $allowed_html = array( 68 64 'fieldset' => array( 69 65 'class' => true, … … 74 70 'label' => array( 75 71 'for' => true, 72 'class' => true, 76 73 ), 77 74 'span' => array( … … 84 81 'value' => true, 85 82 'data-initial-state' => true, 86 ), 87 'select' => array( 83 'step' => true, 84 'min' => true, 85 'max' => true, 86 ), 87 'select' => array( 88 88 'name' => true, 89 89 'id' => true, 90 90 'aria-label' => true, 91 'class' => true, 91 92 ), 92 'option' => array( 93 'value' => true, 94 'selected' => true, 95 ), 93 'option' => array( 94 'value' => true, 95 'selected' => true, 96 ), 97 'textarea' => array( 98 'name' => true, 99 'id' => true, 100 'cols' => true, 101 'rows' => true, 102 ), 96 103 // Add other tags and attributes as needed 97 104 ); 98 99 105 echo wp_kses( bulkedittoolkit_generate_fieldset_start(), $allowed_html ); 100 106 echo wp_kses( bulkedittoolkit_generate_label($post_type, $context), $allowed_html ); 101 107 echo wp_kses( bulkedittoolkit_generate_input_wrapper($post_type, $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type($bulkedittoolkit_current_post_type, $post_type), $html_generators, $context), $allowed_html ); 102 108 echo wp_kses( bulkedittoolkit_generate_fieldset_end(), $allowed_html ); 103 104 109 bulkedittoolkit_debug_log("Added bulk edit field for: " . $post_type, $GLOBALS["bulkedittoolkit_is_debug_active"]); 105 110 } … … 107 112 // Fonctions de génération de HTML 108 113 function bulkedittoolkit_generate_fieldset_start() { 109 // Génération du champ nonce pour la sécurité114 // Génération du champ nonce pour la sécurité 110 115 $nonce_html = wp_nonce_field('update_custom_fields_action', 'update_custom_fields_nonce', true, false); 111 112 116 // Début de la structure HTML pour l'édition en vrac 113 $html = '<fieldset class="inline-edit-col-right">' . 117 $html = '<fieldset class="inline-edit-col-right">' . 114 118 '<div class="inline-edit-col">' . 115 119 $nonce_html; 116 117 120 // Retour du HTML généré 118 121 return $html; 119 /*120 // Inside your function where you generate the HTML for the input or form122 /* 123 // Inside your function where you generate the HTML for the input or form 121 124 echo wp_nonce_field('update_custom_fields_action', 'update_custom_fields_nonce', true, false); 122 125 return '<fieldset class="inline-edit-col-right"><div class="inline-edit-col">';*/ … … 146 149 function bulkedittoolkit_generate_select_html($field_name, $context) { 147 150 global $wpdb, $post; 148 149 151 // Récupérer le post_id (soit via $post, soit via $_REQUEST pour la modification rapide) 150 152 $post_id = isset($post->ID) ? $post->ID : (isset($_REQUEST['post_ID']) ? intval($_REQUEST['post_ID']) : 0); 151 152 153 // Récupérer la valeur actuelle du champ pour ce post 153 154 $current_value = ''; … … 156 157 bulkedittoolkit_debug_log("Valeur actuelle pour $field_name (post_id $post_id) : " . $current_value, $GLOBALS["bulkedittoolkit_is_debug_active"]); 157 158 } 158 159 159 // Récupérer les valeurs distinctes pour le champ 160 160 $results = $wpdb->get_results( … … 165 165 ); 166 166 bulkedittoolkit_debug_log("Valeurs récupérées pour $field_name : " . print_r($results, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 167 168 167 // Créer le select 169 168 $html = '<select name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" aria-label="' . esc_attr__('Select value for ', 'bulk-content-toolkit') . esc_html($field_name) . '">'; 170 171 169 // Ajouter une option par défaut 172 $html .= '<option value=""' . ($current_value === '' ? ' selected' : '') . '>' . esc_html__('Select a value', 'bulk-content-toolkit') . '</option>'; 173 170 $html .= '<option value=""' . ($context === 'bulk' ? '' : ($current_value === '' ? ' selected' : '')) . '>' . ($context === 'bulk' ? esc_html__('— Aucun changement —', 'bulk-content-toolkit') : esc_html__('Select a value', 'bulk-content-toolkit')) . '</option>'; 174 171 // Ajouter les options 175 172 foreach ($results as $result) { … … 180 177 } 181 178 } 182 183 179 $html .= '</select>'; 184 185 180 // Débogage : enregistrer le HTML généré 186 181 bulkedittoolkit_debug_log("HTML généré pour $field_name : $html", $GLOBALS["bulkedittoolkit_is_debug_active"]); 187 188 182 return $html; 189 183 } 190 184 191 185 function bulkedittoolkit_get_value($field_name) { 192 global $wpdb, $post;186 global $wpdb, $post; 193 187 // il faut boucler ici car la valeur récupérée est celle du dernier post id 194 188 // Récupérer la valeur de la base de données pour le post et le champ donnés … … 197 191 $post->ID, $field_name 198 192 )); 199 200 return ($value); 193 return ($value); 201 194 } 202 195 203 196 function bulkedittoolkit_generate_text_html($field_name, $context = '') { 204 205 197 // Si aucune valeur n'est trouvée, $value sera NULL, donc on utilise une chaîne vide par défaut 206 $value = bulkedittoolkit_get_value($field_name) ?? ''; 207 208 return '<input type="text" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 198 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 199 $html = ''; 200 if ($context === 'bulk') { 201 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 202 $html .= '<option value="">— Aucun changement —</option>'; 203 $html .= '<option value="1">Changer pour :</option>'; 204 $html .= '</select>'; 205 $html .= '<label class="change-input" style="display: none;">'; 206 } 207 $html .= '<input type="text" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 208 if ($context === 'bulk') { 209 $html .= '</label>'; 210 } 211 return $html; 209 212 } 210 213 211 214 function bulkedittoolkit_generate_number_html($field_name, $context = '') { 212 213 $value = bulkedittoolkit_get_value($field_name) ?? ''; 214 215 return '<input type="number" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 216 //return '<input type="number" name="' . $field_name . '" id="' . $field_name . '"' . 217 // ($context ? ' data-context="' . htmlspecialchars($context) . '"' : '') . '>'; 215 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 216 $html = ''; 217 if ($context === 'bulk') { 218 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 219 $html .= '<option value="">— Aucun changement —</option>'; 220 $html .= '<option value="1">Changer pour :</option>'; 221 $html .= '</select>'; 222 $html .= '<label class="change-input" style="display: none;">'; 223 } 224 $html .= '<input type="number" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 225 if ($context === 'bulk') { 226 $html .= '</label>'; 227 } 228 //return '<input type="number" name="' . $field_name . '" id="' . $field_name . '"' . 229 // ($context ? ' data-context="' . htmlspecialchars($context) . '"' : '') . '>'; 230 return $html; 218 231 } 219 232 220 233 function bulkedittoolkit_generate_datetime_html($field_name, $context = '') { 221 222 $value = bulkedittoolkit_get_value($field_name) ?? ''; 223 234 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 224 235 // Génération de code HTML pour un sélecteur de date et heure 225 return '<input type="datetime-local" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 236 $html = ''; 237 if ($context === 'bulk') { 238 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 239 $html .= '<option value="">— Aucun changement —</option>'; 240 $html .= '<option value="1">Changer pour :</option>'; 241 $html .= '</select>'; 242 $html .= '<label class="change-input" style="display: none;">'; 243 } 244 $html .= '<input type="datetime-local" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 245 if ($context === 'bulk') { 246 $html .= '</label>'; 247 } 248 return $html; 226 249 } 227 250 228 251 function bulkedittoolkit_generate_radio_html($field_name, $context = '') { 229 230 $value = bulkedittoolkit_get_value($field_name) ?? ''; 231 252 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 232 253 // Générer du HTML pour des boutons radio, ici on suppose une version simplifiée 233 return '<input type="radio" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 254 $html = ''; 255 if ($context === 'bulk') { 256 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 257 $html .= '<option value="">— Aucun changement —</option>'; 258 $html .= '<option value="1">Changer pour :</option>'; 259 $html .= '</select>'; 260 $html .= '<label class="change-input" style="display: none;">'; 261 } 262 $html .= '<input type="radio" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 263 if ($context === 'bulk') { 264 $html .= '</label>'; 265 } 266 return $html; 234 267 } 235 268 236 269 function bulkedittoolkit_generate_textarea_html($field_name, $context = '') { 237 238 $value = bulkedittoolkit_get_value($field_name) ?? ''; 239 240 return '<textarea name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" /textarea>'; 270 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 271 $html = ''; 272 if ($context === 'bulk') { 273 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 274 $html .= '<option value="">— Aucun changement —</option>'; 275 $html .= '<option value="1">Changer pour :</option>'; 276 $html .= '</select>'; 277 $html .= '<label class="change-input" style="display: none;">'; 278 } 279 $html .= '<textarea name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" cols="22" rows="1">' . esc_textarea($value) . '</textarea>'; 280 if ($context === 'bulk') { 281 $html .= '</label>'; 282 } 283 return $html; 241 284 } 242 285 243 286 function bulkedittoolkit_generate_file_html($field_name, $context = '') { 244 245 $value = bulkedittoolkit_get_value($field_name) ?? ''; 246 247 return '<input type="file" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 287 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 288 $html = ''; 289 if ($context === 'bulk') { 290 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 291 $html .= '<option value="">— Aucun changement —</option>'; 292 $html .= '<option value="1">Changer pour :</option>'; 293 $html .= '</select>'; 294 $html .= '<label class="change-input" style="display: none;">'; 295 } 296 $html .= '<input type="file" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 297 if ($context === 'bulk') { 298 $html .= '</label>'; 299 } 300 return $html; 248 301 } 249 302 250 303 function bulkedittoolkit_generate_email_html($field_name, $context = '') { 251 252 $value = bulkedittoolkit_get_value($field_name) ?? ''; 253 254 return '<input type="email" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 304 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 305 $html = ''; 306 if ($context === 'bulk') { 307 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 308 $html .= '<option value="">— Aucun changement —</option>'; 309 $html .= '<option value="1">Changer pour :</option>'; 310 $html .= '</select>'; 311 $html .= '<label class="change-input" style="display: none;">'; 312 } 313 $html .= '<input type="email" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 314 if ($context === 'bulk') { 315 $html .= '</label>'; 316 } 317 return $html; 255 318 } 256 319 257 320 function bulkedittoolkit_generate_password_html($field_name, $context = '') { 258 259 $value = bulkedittoolkit_get_value($field_name) ?? ''; 260 261 return '<input type="password" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 321 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 322 $html = ''; 323 if ($context === 'bulk') { 324 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 325 $html .= '<option value="">— Aucun changement —</option>'; 326 $html .= '<option value="1">Changer pour :</option>'; 327 $html .= '</select>'; 328 $html .= '<label class="change-input" style="display: none;">'; 329 } 330 $html .= '<input type="password" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 331 if ($context === 'bulk') { 332 $html .= '</label>'; 333 } 334 return $html; 262 335 } 263 336 264 337 function bulkedittoolkit_generate_url_html($field_name, $context = '') { 265 266 $value = bulkedittoolkit_get_value($field_name) ?? ''; 267 268 return '<input type="url" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 338 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 339 $html = ''; 340 if ($context === 'bulk') { 341 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 342 $html .= '<option value="">— Aucun changement —</option>'; 343 $html .= '<option value="1">Changer pour :</option>'; 344 $html .= '</select>'; 345 $html .= '<label class="change-input" style="display: none;">'; 346 } 347 $html .= '<input type="url" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 348 if ($context === 'bulk') { 349 $html .= '</label>'; 350 } 351 return $html; 269 352 } 270 353 271 354 function bulkedittoolkit_generate_color_html($field_name, $context = '') { 272 273 $value = bulkedittoolkit_get_value($field_name) ?? ''; 274 275 return '<input type="color" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 355 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 356 $html = ''; 357 if ($context === 'bulk') { 358 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 359 $html .= '<option value="">— Aucun changement —</option>'; 360 $html .= '<option value="1">Changer pour :</option>'; 361 $html .= '</select>'; 362 $html .= '<label class="change-input" style="display: none;">'; 363 } 364 $html .= '<input type="color" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 365 if ($context === 'bulk') { 366 $html .= '</label>'; 367 } 368 return $html; 276 369 } 277 370 278 371 function bulkedittoolkit_generate_range_html($field_name, $context = '') { 279 280 $value = bulkedittoolkit_get_value($field_name) ?? ''; 281 372 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 282 373 // Ici, on doit définir un min, max, et step pour que le range fonctionne correctement 283 return '<input type="range" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" min="0" max="100" step="1"' . '" value="' . esc_attr($value) . '" />'; 374 $html = ''; 375 if ($context === 'bulk') { 376 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 377 $html .= '<option value="">— Aucun changement —</option>'; 378 $html .= '<option value="1">Changer pour :</option>'; 379 $html .= '</select>'; 380 $html .= '<label class="change-input" style="display: none;">'; 381 } 382 $html .= '<input type="range" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" min="0" max="100" step="1" value="' . esc_attr($value) . '" />'; 383 if ($context === 'bulk') { 384 $html .= '</label>'; 385 } 386 return $html; 284 387 } 285 388 … … 298 401 }, 10, 1); 299 402 300 // Save Quick Edit 403 // Save Quick Edit 301 404 function bulkedittoolkit_save_custom_quick_edit($post_id) { 302 405 global $bulkedittoolkit_bulk_edit_settings, $bulkedittoolkit_field_function_map; … … 314 417 continue; // Passe au champ suivant si la fonction n'est pas trouvée 315 418 } 316 317 419 // Récupérer le nom de la fonction mappée au nom du champ 318 420 $function_name = $bulkedittoolkit_field_function_map[$field_name]; 319 320 421 // Vérifier si la requête contient la valeur du champ et si elle est active 321 422 $request_key = "custom_" . $field_name;//get_bulk_edit_field_name($bulkedittoolkit_current_post_type);//$field_name); … … 336 437 //} 337 438 } 338 else {439 else { 339 440 call_user_func($function_name, $post_id, $field_name, false); 340 }441 } 341 442 } 342 443 } … … 349 450 // Vérification de nonce pour la sécurité 350 451 check_admin_referer('update_custom_fields_nonce'); 351 352 452 // Vérifier les permissions de l'utilisateur 353 453 if (!current_user_can('edit_posts')) { … … 357 457 if (isset($_POST['post_id'])) { 358 458 $post_id = intval($_POST['post_id']); // Sanitize post ID to ensure it's an integer 359 360 459 if (get_post($post_id)) { // Check if the post exists 361 460 foreach ($_POST as $key => $value) { -
bulk-content-toolkit/tags/1.2.2/includes/core-functions.php
r3188505 r3349434 10 10 $message = print_r($message, true); 11 11 } 12 error_log( $message);12 error_log("[bct]:" . $message); 13 13 } 14 14 } -
bulk-content-toolkit/tags/1.2.2/includes/utils/helpers.php
r3188505 r3349434 28 28 // Construit la clé de métadonnée avec un underscore au début si nécessaire 29 29 $meta_key = $field_name;//'_' . $prefix . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name'); 30 30 $current_value = get_post_meta($post_id, $meta_key, true); 31 bulkedittoolkit_debug_log("Current value for $meta_key on post $post_id before update: $current_value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 31 32 // Met à jour la métadonnée du post 32 update_post_meta($post_id, $meta_key, $status); 33 33 $result = update_post_meta($post_id, $meta_key, $status); 34 bulkedittoolkit_debug_log("Update result for $meta_key on post $post_id with $status: " . var_export($result, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 35 $new_value = get_post_meta($post_id, $meta_key, true); 36 bulkedittoolkit_debug_log("New value for $meta_key on post $post_id after update: $new_value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 34 37 bulkedittoolkit_debug_log("Setting {$meta_key} to {$status} for post ID {$post_id}", $GLOBALS["bulkedittoolkit_is_debug_active"]); 35 38 if ($all) { -
bulk-content-toolkit/tags/1.2.2/js/bulk-edit-admin.js
r3188505 r3349434 1 1 document.addEventListener('DOMContentLoaded', function() { 2 // Gestion des champs <select> change_to pour les inputs et textareas (sauf checkboxes) 3 const changeToSelects = document.querySelectorAll('.change_to'); 4 changeToSelects.forEach(select => { 5 const fieldName = select.name.replace('change_custom_', 'custom_'); 6 const input = document.querySelector(`[name="${fieldName}"]`); 7 if (input && input.type !== 'checkbox') { 8 select.addEventListener('change', () => { 9 const inputLabel = input.closest('.change-input'); 10 if (select.value === '1') { 11 inputLabel.style.display = 'inline-block'; 12 } else { 13 inputLabel.style.display = 'none'; 14 input.value = ''; 15 } 16 }); 17 } 18 }); 19 20 // Le reste du fichier reste inchangé 2 21 const postTypeSelect = document.getElementById('post_type'); 3 22 const fieldNameContainer = document.getElementById('field-selection-container'); 4 5 23 function updateFields(postType) { 6 24 const data = { 7 25 action: 'update_fields_for_post_type', 8 26 post_type: postType, 9 nonce: bulkEditAdmin.nonce27 nonce: bulkEditAdmin.nonce 10 28 }; 11 12 fetch(ajaxurl, {13 method: 'POST',14 credentials: 'same-origin',15 headers: {16 'Content-Type': 'application/x-www-form-urlencoded',17 },18 body: new URLSearchParams(data).toString()19 })20 .then(response => response.json()) // Supposons que nous recevons un JSON avec les champs21 .then(data => {22 updateFieldSelection(data.fields, 0);23 })24 .catch(error => console.error('Error:', error));25 }26 27 function updateFieldSelection(fields, $available_or_selected) {28 const availableFieldsList = document.getElementById('available-fields').querySelector('ul');29 const selectFieldsList = document.getElementById('selected-fields').querySelector('ul');30 if ($available_or_selected === 0)31 availableFieldsList.innerHTML = ''; // Vider la liste actuelle32 else33 selectFieldsList.innerHTML = '';34 35 fields.forEach(field => {36 const li = document.createElement('li');37 li.textContent = field;38 li.dataset.field = field;39 if ($available_or_selected === 0)40 availableFieldsList.appendChild(li);41 else42 selectFieldsList.appendChild(li);43 });44 45 // Optionnel : Si vous voulez réinitialiser ou maintenir les champs sélectionnés46 //const selectedFieldsList = document.getElementById('selected-fields').querySelector('ul');47 //selectedFieldsList.innerHTML = ''; // Ou réinitialiser en fonction de la logique du backend48 }49 50 function loadSelectedFields(postType) {51 const data = {52 action: 'load_selected_fields',53 post_type: postType,54 nonce: bulkEditAdmin.nonce55 };56 57 29 fetch(ajaxurl, { 58 30 method: 'POST', … … 65 37 .then(response => response.json()) 66 38 .then(data => { 67 //const selectedFieldsList = document.getElementById('selected-fields').querySelector('ul'); 68 //selectedFieldsList.innerHTML = ''; 39 updateFieldSelection(data.fields, 0); 40 }) 41 .catch(error => console.error('Error:', error)); 42 } 43 function updateFieldSelection(fields, $available_or_selected) { 44 const availableFieldsList = document.getElementById('available-fields').querySelector('ul'); 45 const selectFieldsList = document.getElementById('selected-fields').querySelector('ul'); 46 if ($available_or_selected === 0) 47 availableFieldsList.innerHTML = ''; 48 else 49 selectFieldsList.innerHTML = ''; 50 fields.forEach(field => { 51 const li = document.createElement('li'); 52 li.textContent = field; 53 li.dataset.field = field; 54 if ($available_or_selected === 0) 55 availableFieldsList.appendChild(li); 56 else 57 selectFieldsList.appendChild(li); 58 }); 59 } 60 function loadSelectedFields(postType) { 61 const data = { 62 action: 'load_selected_fields', 63 post_type: postType, 64 nonce: bulkEditAdmin.nonce 65 }; 66 fetch(ajaxurl, { 67 method: 'POST', 68 credentials: 'same-origin', 69 headers: { 70 'Content-Type': 'application/x-www-form-urlencoded', 71 }, 72 body: new URLSearchParams(data).toString() 73 }) 74 .then(response => response.json()) 75 .then(data => { 69 76 if(data.fields) { 70 77 updateFieldSelection(data.fields, 1); … … 73 80 .catch(error => console.error('Error loading selected fields:', error)); 74 81 } 75 76 82 if(postTypeSelect && fieldNameContainer) { 77 83 postTypeSelect.addEventListener('change', function(e) { 78 loadSelectedFields(this.value);84 loadSelectedFields(this.value); 79 85 updateFields(this.value); 80 86 }); 81 loadSelectedFields(postTypeSelect.value); 82 // Trigger au chargement initial 87 loadSelectedFields(postTypeSelect.value); 83 88 updateFields(postTypeSelect.value); 84 85 // Logique pour bouger les champs ici ou dans une autre fonction si besoin86 89 document.querySelectorAll('.field-list ul').forEach(list => { 87 90 list.addEventListener('click', (e) => { … … 92 95 }); 93 96 } 94 95 // Définir ces variables après avoir assuré que le DOM est chargé et après avoir potentiellement modifié le contenu avec vos fonctions.96 const availableFields = document.getElementById('available-fields').querySelector('ul');97 const selectedFields = document.getElementById('selected-fields').querySelector('ul');98 99 97 function moveFields(direction) { 100 const availableFields = document.getElementById('available-fields').querySelector('ul'); 101 const selectedFields = document.getElementById('selected-fields').querySelector('ul'); 102 103 let fromList = direction === 'right' ? availableFields : selectedFields; 104 let toList = direction === 'right' ? selectedFields : availableFields; 105 106 Array.from(fromList.querySelectorAll('li.selected')).forEach(field => { 107 let fieldValue = field.dataset.field; 108 let alreadyExists = Array.from(toList.querySelectorAll('li')).some(existingField => existingField.dataset.field === fieldValue); 109 110 if (!alreadyExists || direction === 'left') { 111 field.classList.remove('selected'); 112 let newField = field.cloneNode(true); 113 if(direction === 'right') { 114 newField.innerHTML += '<input type="hidden" name="bulk_edit_settings[fields][]" value="' + fieldValue + '">'; 98 const availableFields = document.getElementById('available-fields').querySelector('ul'); 99 const selectedFields = document.getElementById('selected-fields').querySelector('ul'); 100 let fromList = direction === 'right' ? availableFields : selectedFields; 101 let toList = direction === 'right' ? selectedFields : availableFields; 102 Array.from(fromList.querySelectorAll('li.selected')).forEach(field => { 103 let fieldValue = field.dataset.field; 104 let alreadyExists = Array.from(toList.querySelectorAll('li')).some(existingField => existingField.dataset.field === fieldValue); 105 if (!alreadyExists || direction === 'left') { 106 field.classList.remove('selected'); 107 let newField = field.cloneNode(true); 108 if(direction === 'right') { 109 newField.innerHTML += '<input type="hidden" name="bulk_edit_settings[fields][]" value="' + fieldValue + '">'; 110 } 111 toList.appendChild(newField); 112 if(direction === 'left') { 113 field.remove(); 114 } 115 } else if(direction === 'right') { 116 console.log('Field already exists in selected list:', fieldValue); 115 117 } 116 toList.appendChild(newField); 117 if(direction === 'left') { 118 field.remove(); 118 }); 119 if(document.querySelector('#selected-fields ul li') !== null) { 120 saveFields(); 121 } else { 122 const postType = document.getElementById('post_type').value; 123 removePostTypeFromTable(postType); 124 } 125 } 126 function saveFields() { 127 const selectedFieldsList = document.querySelectorAll('#selected-fields ul li'); 128 const postType = document.getElementById('post_type').value; 129 const data = { 130 'action': 'bulk_edit_fields_save', 131 'post_type': postType, 132 'fields': Array.from(selectedFieldsList).map(li => li.dataset.field), 133 'nonce': bulkEditAdmin.nonce 134 }; 135 fetch(ajaxurl, { 136 method: 'POST', 137 credentials: 'same-origin', 138 headers: { 139 'Content-Type': 'application/x-www-form-urlencoded', 140 }, 141 body: new URLSearchParams(data).toString() 142 }) 143 .then(response => response.json()) 144 .then(response => { 145 const banner = document.createElement('div'); 146 banner.style.cssText = ` 147 position: fixed; 148 top: ${window.adminbar ? '64px' : '32px'}; 149 left: 0; 150 right: 0; 151 text-align: center; 152 background-color: ${response.success ? 'green' : 'red'}; 153 color: white; 154 padding: 10px; 155 z-index: 1000; 156 `; 157 banner.textContent = response.success ? 'Sauvegarde Ok' : 'Contenu identique déjà existant'; 158 document.body.appendChild(banner); 159 setTimeout(() => { 160 document.body.removeChild(banner); 161 }, 3000); 162 }) 163 .catch(error => { 164 console.error('Error saving fields:', error); 165 }); 166 } 167 function removePostTypeFromTable(postType) { 168 const nonce = document.querySelector('#bulk_edit_nonce').value; 169 const data = { 170 action: 'remove_post_type_from_bulk_edit', 171 post_type: postType, 172 nonce: nonce 173 }; 174 fetch(ajaxurl, { 175 method: 'POST', 176 credentials: 'same-origin', 177 headers: { 178 'Content-Type': 'application/x-www-form-urlencoded', 179 }, 180 body: new URLSearchParams(data).toString() 181 }) 182 .then(response => response.json()) 183 .then(response => { 184 if(response.success) { 185 console.log('Post type removed from bulk edit settings:', postType); 186 } else { 187 console.error('Failed to remove post type:', response.message); 119 188 } 120 } else if(direction === 'right') { 121 console.log('Field already exists in selected list:', fieldValue); 122 } 123 }); 124 125 if(document.querySelector('#selected-fields ul li') !== null) { 126 saveFields(); 189 }) 190 .catch(error => console.error('Error removing post type:', error)); 127 191 } 128 else {129 const postType = document.getElementById('post_type').value;130 // Logique pour supprimer le post_type de la table s'il n'a pas de champs sélectionnés131 removePostTypeFromTable(postType);132 }133 }134 135 function saveFields() {136 const selectedFieldsList = document.querySelectorAll('#selected-fields ul li');137 const postType = document.getElementById('post_type').value;138 const data = {139 'action': 'bulk_edit_fields_save',140 'post_type': postType,141 'fields': Array.from(selectedFieldsList).map(li => li.dataset.field),142 'nonce': bulkEditAdmin.nonce143 };144 145 fetch(ajaxurl, {146 method: 'POST',147 credentials: 'same-origin',148 headers: {149 'Content-Type': 'application/x-www-form-urlencoded',150 },151 body: new URLSearchParams(data).toString()152 })153 .then(response => response.json())154 .then(response => {155 const banner = document.createElement('div');156 banner.style.cssText = `157 position: fixed;158 top: ${window.adminbar ? '64px' : '32px'}; /* 32px est la hauteur de la barre admin en mode desktop */159 left: 0;160 right: 0;161 text-align: center;162 background-color: ${response.success ? 'green' : 'red'};163 color: white;164 padding: 10px;165 z-index: 1000;166 `;167 banner.textContent = response.success ? 'Sauvegarde Ok' : 'Contenu identique déjà existant';168 document.body.appendChild(banner);169 170 setTimeout(() => {171 document.body.removeChild(banner);172 }, 3000);173 })174 .catch(error => {175 console.error('Error saving fields:', error);176 });177 }178 179 function removePostTypeFromTable(postType) {180 // Récupérer le nonce généré par WordPress181 const nonce = document.querySelector('#bulk_edit_nonce').value; // Assurez-vous que ce champ ou un moyen similaire existe pour obtenir le nonce182 const data = {183 action: 'remove_post_type_from_bulk_edit',184 post_type: postType,185 nonce: nonce186 };187 188 fetch(ajaxurl, {189 method: 'POST',190 credentials: 'same-origin',191 headers: {192 'Content-Type': 'application/x-www-form-urlencoded',193 },194 body: new URLSearchParams(data).toString()195 })196 .then(response => response.json())197 .then(response => {198 if(response.success) {199 console.log('Post type removed from bulk edit settings:', postType);200 // Peut-être mettre à jour l'UI pour refléter le changement201 } else {202 console.error('Failed to remove post type:', response.message);203 }204 })205 .catch(error => console.error('Error removing post type:', error));206 }207 /*208 // Et assurez-vous que l'événement est attaché comme suit:209 document.querySelectorAll('.arrow-btn').forEach(button => {210 button.addEventListener('click', function(event) {211 event.preventDefault();212 const direction = this.dataset.direction;213 moveFields(direction);214 });215 });216 */217 // Attachement des événements aux boutons de flèche218 192 document.querySelectorAll('.arrow-btn').forEach(button => { 219 193 button.addEventListener('click', function(event) { -
bulk-content-toolkit/tags/1.2.2/js/user.js
r3349071 r3349434 1 1 jQuery(document).ready(function($) { 2 // Surveiller l'apparition du formulaire Bulk Edit 3 const observer = new MutationObserver((mutations, observer) => { 4 mutations.forEach(mutation => { 5 if (mutation.addedNodes.length) { 6 const bulkForm = document.querySelector('.bulk-edit-row'); 7 if (bulkForm) { 8 // Formulaire trouvé, exécuter la logique 9 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 10 if (typeof bulkEditFieldNames === 'string') { 11 bulkEditFieldNames = {default: bulkEditFieldNames}; 12 } 13 const bulkItems = document.querySelectorAll('.ntdelitem button[id^="_"]'); 14 if (bulkItems.length === 0) return; 15 let postIds = Array.from(bulkItems).map(button => button.id.slice(1)); 16 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 17 // Ignorer _edit_lock 18 if (fieldName === '_edit_lock') { 19 console.log('Skipping _edit_lock to prevent interference'); 20 return; 21 } 22 const bulkEditId = `bulk_edit_${fieldName}_bulk`; 23 const bulkEditSwitch = document.querySelector('#' + bulkEditId + '[type="checkbox"]'); 24 const bulkEditInput = document.querySelector('#' + bulkEditId + ':not([type="checkbox"])'); 25 if (bulkEditSwitch) { 26 $.ajax({ 27 type: 'POST', 28 url: UserScriptParams.ajaxUrl, 29 data: { 30 action: 'get_bulk_edit_statuses', 31 post_ids: postIds, 32 field_name: fieldName, 33 nonce: UserScriptParams.nonce 34 }, 35 success: function(response) { 36 if (response.success) { 37 let allYes = true, allNo = true; 38 response.data.forEach(status => { 39 if (status !== 'yes' && status !== '1' && status !== true) allYes = false; 40 if (status !== 'no' && status !== '' && status !== false) allNo = false; 41 }); 42 if (allYes) { 43 bulkEditSwitch.indeterminate = false; 44 bulkEditSwitch.checked = true; 45 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 46 bulkEditSwitch.setAttribute('value', 'yes'); 47 bulkEditSwitch.removeAttribute('data-indeterminate'); 48 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 49 } else if (allNo) { 50 bulkEditSwitch.indeterminate = false; 51 bulkEditSwitch.checked = false; 52 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 53 bulkEditSwitch.setAttribute('value', 'no'); 54 bulkEditSwitch.removeAttribute('data-indeterminate'); 55 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 56 } else { 57 bulkEditSwitch.indeterminate = true; 58 bulkEditSwitch.checked = false; 59 bulkEditSwitch.removeAttribute('name'); 60 bulkEditSwitch.setAttribute('data-indeterminate', 'true'); 61 bulkEditSwitch.parentNode.classList.add('indeterminate'); 62 } 63 } else { 64 console.log('Failed to get statuses for field:', fieldName); 65 } 66 }, 67 error: function(error) { 68 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 69 } 70 }); 71 } else if (bulkEditInput) { 72 $.ajax({ 73 type: 'POST', 74 url: UserScriptParams.ajaxUrl, 75 data: { 76 action: 'get_bulk_edit_statuses', 77 post_ids: postIds, 78 field_name: fieldName, 79 nonce: UserScriptParams.nonce 80 }, 81 success: function(response) { 82 if (response.success) { 83 let allSame = true; 84 let firstValue = response.data[0]; 85 response.data.forEach(status => { 86 if (status !== firstValue) allSame = false; 87 }); 88 if (allSame && firstValue !== '' && firstValue !== null && firstValue !== false) { 89 bulkEditInput.value = firstValue; 90 } else { 91 bulkEditInput.value = ''; 92 } 93 } else { 94 console.log('Failed to get statuses for field:', fieldName); 95 } 96 }, 97 error: function(error) { 98 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 99 } 100 }); 101 } else { 102 console.log(`Field ${fieldName} not found as switch or input.`); 103 } 104 /*// Forcer _manage_stock à 'yes' si _stock est modifié 105 if (fieldName === '_stock') { 106 const manageStockSwitch = document.querySelector('#bulk_edit_custom__manage_stock_bulk[type="checkbox"]'); 107 if (manageStockSwitch && bulkEditInput && bulkEditInput.value !== '') { 108 manageStockSwitch.indeterminate = false; 109 manageStockSwitch.checked = true; 110 manageStockSwitch.setAttribute('name', 'custom__manage_stock'); 111 manageStockSwitch.setAttribute('value', 'yes'); 112 manageStockSwitch.removeAttribute('data-indeterminate'); 113 manageStockSwitch.parentNode.classList.remove('indeterminate'); 114 // Afficher le champ _stock 115 const stockField = document.querySelector('.stock_qty_field'); 116 if (stockField) stockField.style.display = 'block'; 117 } 118 }*/ 119 }); 120 // Arrêter l'observation une fois le formulaire traité 121 observer.disconnect(); 122 } 123 } 124 }); 125 }); 126 127 // Lancer l'observation sur le conteneur parent 128 observer.observe(document.body, { 129 childList: true, 130 subtree: true 131 }); 132 133 // Gérer le Quick Edit pour charger les valeurs correctes 2 134 $(document).on('click', '.editinline', function() { 3 135 var post_id = $(this).closest('tr').attr('id').replace("post-", ""); 4 136 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 5 137 if (typeof bulkEditFieldNames === 'string') { 138 bulkEditFieldNames = {default: bulkEditFieldNames}; 139 } 140 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 141 if (fieldName === '_edit_lock') return; 142 $.ajax({ 143 url: UserScriptParams.ajaxUrl, 144 type: 'POST', 145 data: { 146 action: 'get_quick_edit_status', 147 post_id: post_id, 148 field_name: key, 149 nonce: UserScriptParams.nonce 150 }, 151 success: function(response) { 152 var selector = '#edit-' + post_id + ' [name="custom_' + fieldName + '"]'; 153 var $element = $(selector); 154 if ($element.is(':checkbox')) { 155 $element.prop('checked', response === 'yes' || response == 1 || response === true || response === '1'); 156 $element.removeAttr('data-indeterminate'); 157 $element.parent().removeClass('indeterminate'); 158 } else { 159 $element.val(response); 160 } 161 // Afficher le champ _stock si _manage_stock est coché 162 if (fieldName === '_manage_stock' && (response === 'yes' || response == 1 || response === true || response === '1')) { 163 const stockField = document.querySelector('#edit-' + post_id + ' .stock_qty_field'); 164 if (stockField) stockField.style.display = 'block'; 165 } 166 }, 167 error: function(error) { 168 console.log('Error fetching quick edit status for field ' + key + ':', error); 169 } 170 }); 171 }); 172 }); 173 }); 174 175 176 /*jQuery(document).ready(function($) { 177 $(document).on('click', '.editinline', function() { 178 var post_id = $(this).closest('tr').attr('id').replace("post-", ""); 179 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 6 180 if (typeof bulkEditFieldNames === 'string') { 7 181 bulkEditFieldNames = {default: bulkEditFieldNames}; // Convertir en objet si c'est un string 8 182 } 9 10 183 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 11 184 $.ajax({ … … 16 189 'post_id': post_id, 17 190 'field_name': key, // Utilise la clé comme nom du champ pour l'ajax 18 'nonce': UserScriptParams.nonce // Ajouter le nonce pour la sécurité191 'nonce': UserScriptParams.nonce // Ajouter le nonce pour la sécurité 19 192 }, 20 193 success: function(response) { 21 //var checkedState = (response /*.data*/ === 'yes' || response === 1 || response === true); // Supposons que 'response' maintenant contient 'data'22 // Corriger le sélecteur pour cibler <input> ou <select>23 194 var selector = '#edit-' + post_id + ' [name="' + fieldName + '"]'; 24 //var selector = '#edit-' + post_id + ' input[name="' + fieldName + '"]'; 25 var $element = $(selector); //console.log($element);console.log("sdfghj"); 26 195 var $element = $(selector); 27 196 if ($element.is(':checkbox')) { 28 $element.prop('checked', response === 'yes' || response == 1 || response === true ); // Notez l'utilisation de '==' pour la comparaison loose197 $element.prop('checked', response === 'yes' || response == 1 || response === true || response === '1'); 29 198 } else if ($element.is('select')) { 30 //console.log("RESPONSE for " + fieldName + " (post_id " + post_id + "): ", response);31 // Gérer à la fois une réponse brute et une réponse structurée32 199 var value = typeof response === 'string' ? response : 33 200 (response && response.data && response.data[fieldName.replace('custom_', '')] && … … 35 202 response.data[fieldName.replace('custom_', '')].value : ''); 36 203 $element.val(value); 37 ///console.log("Valeur appliquée pour " + fieldName + ": ", value); 38 } else { // Par défaut, on suppose que c'est un input text 204 } else { 39 205 $element.val(response); 40 206 } 41 //$(selector).prop('checked', checkedState);42 207 }, 43 208 error: function(error) { … … 51 216 document.addEventListener('click', function(event) { 52 217 if (event.target.matches('.bulkactions #doaction, .bulkactions #doaction2')) { 53 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 54 218 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 55 219 if (typeof bulkEditFieldNames === 'string') { 56 220 bulkEditFieldNames = {default: bulkEditFieldNames}; // Convertir en objet si c'est un string 57 221 } 58 59 setTimeout(function() { 222 function() { 60 223 const bulkItems = document.querySelectorAll('.ntdelitem button[id^="_"]'); 61 224 if (bulkItems.length === 0) return; 62 63 225 let postIds = Array.from(bulkItems).map(button => button.id.slice(1)); 64 65 226 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 66 227 const bulkEditId = `bulk_edit_${fieldName}_bulk`; 67 const bulkEditSwitch = document.querySelector('#' + bulkEditId); 228 const bulkEditSwitch = document.querySelector('#' + bulkEditId + '[type="checkbox"]'); 229 const bulkEditSelect = document.querySelector('#' + bulkEditId + '[type="select"]'); 68 230 69 231 if (bulkEditSwitch) { 232 // Handle checkbox fields 70 233 jQuery.ajax({ 71 234 type: 'POST', … … 75 238 post_ids: postIds, 76 239 field_name: fieldName, 77 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité240 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité 78 241 }, 79 242 success: function(response) { 80 243 if (response.success) { 81 244 let allYes = true, allNo = true; 82 83 245 response.data.forEach(status => { 84 if (status !== 'yes' ) allYes = false;85 if (status !== 'no' ) allNo = false;246 if (status !== 'yes' && status !== '1' && status !== true) allYes = false; 247 if (status !== 'no' && status !== '' && status !== false) allNo = false; 86 248 }); 87 88 249 if (allYes) { 89 250 bulkEditSwitch.indeterminate = false; 90 251 bulkEditSwitch.checked = true; 252 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 253 bulkEditSwitch.setAttribute('value', 'yes'); 254 bulkEditSwitch.removeAttribute('data-indeterminate'); 255 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 91 256 } else if (allNo) { 92 257 bulkEditSwitch.indeterminate = false; 93 258 bulkEditSwitch.checked = false; 259 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 260 bulkEditSwitch.setAttribute('value', 'no'); 261 bulkEditSwitch.removeAttribute('data-indeterminate'); 262 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 94 263 } else { 95 264 bulkEditSwitch.indeterminate = true; 96 265 bulkEditSwitch.checked = false; 266 bulkEditSwitch.removeAttribute('name'); 267 bulkEditSwitch.setAttribute('data-indeterminate', 'true'); 268 bulkEditSwitch.parentNode.classList.add('indeterminate'); 269 } 270 } else { 271 console.log('Failed to get statuses for field:', fieldName); 272 } 273 }, 274 error: function(error) { 275 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 276 } 277 }); 278 } else if (bulkEditSelect) { 279 // Handle select fields 280 jQuery.ajax({ 281 type: 'POST', 282 url: UserScriptParams.ajaxUrl, 283 data: { 284 action: 'get_bulk_edit_statuses', 285 post_ids: postIds, 286 field_name: fieldName, 287 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité 288 }, 289 success: function(response) { 290 if (response.success) { 291 // Check if all posts have the same value 292 let allSame = true; 293 let firstValue = response.data[0]; 294 response.data.forEach(status => { 295 if (status !== firstValue) allSame = false; 296 }); 297 if (allSame && firstValue !== '' && firstValue !== null && firstValue !== false) { 298 // If all posts have the same non-empty value, select it 299 bulkEditSelect.value = firstValue; 300 } else { 301 // Otherwise, select "— Aucun changement —" (empty value) 302 bulkEditSelect.value = ''; 97 303 } 98 304 } else { … … 105 311 }); 106 312 } else { 107 console.log(` Switch for ${fieldName} not found.`);313 console.log(`Field ${fieldName} not found as switch or select.`); 108 314 } 109 315 }); 110 } , 100);316 }; 111 317 } 318 });*/ 319 320 // Add event listener for checkbox toggle on slider click 321 /*document.addEventListener('DOMContentLoaded', function() { 322 document.querySelectorAll('.bulk-edit-checkbox .slider').forEach(slider => { 323 slider.addEventListener('click', function(event) { 324 const checkbox = this.previousElementSibling; // Get the checkbox input 325 if (checkbox && checkbox.type === 'checkbox') { 326 checkbox.checked = !checkbox.checked; // Toggle the checkbox state 327 checkbox.indeterminate = false; // Clear indeterminate state 328 checkbox.removeAttribute('data-indeterminate'); // Clear indeterminate tracking 329 checkbox.parentNode.classList.remove('indeterminate'); 330 // Ensure correct form submission behavior 331 if (checkbox.checked) { 332 checkbox.setAttribute('name', 'custom_' + checkbox.id.replace('bulk_edit_custom_', '').replace('_bulk', '')); 333 checkbox.setAttribute('value', 'yes'); 334 } else { 335 checkbox.setAttribute('name', 'custom_' + checkbox.id.replace('bulk_edit_custom_', '').replace('_bulk', '')); 336 checkbox.setAttribute('value', 'no'); // Explicitly send 'no' for unchecked 337 } 338 } 339 }); 340 }); 112 341 }); 342 */ -
bulk-content-toolkit/tags/1.2.2/readme.txt
r3349072 r3349434 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.4 8 Stable Tag: 1.2. 18 Stable Tag: 1.2.2 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 46 46 47 47 == Changelog == 48 49 = 1.2.2 = 50 - **Improved: Clearer Bulk Interface. The goal is to Bulk Edit right ? 48 51 49 52 = 1.2.1 = -
bulk-content-toolkit/trunk/bulk-content-toolkit.php
r3349072 r3349434 3 3 Plugin Name: Bulk Content Toolkit 4 4 Description: 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. 15 Version: 1.2.2 6 6 Requires at least: 5.0 7 7 Tested up to: 6.8 … … 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html 14 14 */ 15 16 15 defined('ABSPATH') or die('No script kiddies please!'); 17 18 16 // Initialisation de la classe avant les includes 19 17 require_once plugin_dir_path(__FILE__) . 'includes/classes/BulkEditSettings.php'; … … 27 25 require_once plugin_dir_path(__FILE__) . 'includes/api/ajax-handlers.php'; 28 26 require_once plugin_dir_path(__FILE__) . 'includes/utils/helpers.php'; 29 30 27 // Hook pour la fonction d'activation 31 28 register_activation_hook(__FILE__, 'bulkedittoolkit_bulk_edit_plugin_activate'); 32 33 29 function bulkedittoolkit_bulk_edit_plugin_activate() { 34 30 global $wpdb; 35 36 31 $table_name = $wpdb->prefix . 'bulkedittoolkit_plugin_bulk_edit_settings'; 37 38 32 $charset_collate = $wpdb->get_charset_collate(); 39 40 33 $sql = "CREATE TABLE $table_name ( 41 34 id INT(11) UNSIGNED AUTO_INCREMENT, … … 43 36 field_name VARCHAR(255) NOT NULL, 44 37 input_type ENUM( 45 'text', 'password', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 46 'number', 'email', 'url', 'search', 'tel', 'color', 38 'text', 'password', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 39 'number', 'email', 'url', 'search', 'tel', 'color', 47 40 'checkbox', 'radio', 'file', 'hidden', 'image', 'button', 'reset', 'submit', 48 41 'range', 'textarea', 'select', 'label', 'fieldset', 'legend', 49 42 'json', 'editor', 'slider', 'toggle', 'datepicker', 'timepicker' 50 43 ) NOT NULL, 51 PRIMARY KEY (id),44 PRIMARY KEY (id), 52 45 UNIQUE KEY unique_post_type_field_name (post_type, field_name) 53 46 ) $charset_collate;"; 54 55 47 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 56 48 dbDelta($sql); 57 58 49 add_option('bulkedittoolkit_bulk_edit_plugin_version', '1.0'); 59 50 } 60 61 51 register_deactivation_hook(__FILE__, 'bulkedittoolkit_bulk_edit_plugin_deactivate'); 62 63 52 function bulkedittoolkit_bulk_edit_plugin_deactivate() { 64 53 add_action('admin_notices', 'bulkedittoolkit_bulk_edit_deactivation_warning'); 65 // Ajoutez ici la logique pour vérifier si le plugin est en cours de désactivation66 54 if (isset($_POST['confirm_delete_bulk_settings']) || isset($_POST['cancel_delete_bulk_settings'])) { 67 if (wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { 68 bulkedittoolkit_bulk_edit_handle_deactivation_form(); 69 } 70 } 71 } 72 55 if (wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { 56 bulkedittoolkit_bulk_edit_handle_deactivation_form(); 57 } 58 } 59 } 73 60 function bulkedittoolkit_bulk_edit_deactivation_warning() { 74 $nonce = wp_create_nonce('bulk_edit_settings_nonce');61 $nonce = wp_create_nonce('bulk_edit_settings_nonce'); 75 62 ?> 76 63 <div class="notice notice-warning is-dismissible"> 77 64 <p><?php esc_html_e('Attention : Si vous désactivez ce plugin, vous pouvez perdre les paramètres de masse enregistrés. Voulez-vous vraiment supprimer les données de Bulk Edit ?', 'bulk-content-toolkit'); ?></p> 78 65 <form method="post" action=""> 79 <?php wp_nonce_field('bulk_edit_settings_nonce'); ?>66 <?php wp_nonce_field('bulk_edit_settings_nonce'); ?> 80 67 <input type="submit" name="confirm_delete_bulk_settings" class="button button-primary" value="<?php esc_attr_e('Confirmer la suppression', 'bulk-content-toolkit'); ?>"> 81 68 <input type="submit" name="cancel_delete_bulk_settings" class="button" value="<?php esc_attr_e('Annuler', 'bulk-content-toolkit'); ?>"> … … 84 71 <?php 85 72 } 86 87 73 function bulkedittoolkit_bulk_edit_handle_deactivation_form() { 88 74 if (isset($_POST['confirm_delete_bulk_settings']) && wp_verify_nonce($_POST['_wpnonce'], 'bulk_edit_settings_nonce')) { … … 93 79 } 94 80 } 95 96 81 function bulkedittoolkit_bulk_edit_delete_table() { 97 82 global $wpdb; … … 99 84 $wpdb->query("DROP TABLE IF EXISTS $table_name"); 100 85 delete_option('bulkedittoolkit_bulk_edit_plugin_version'); 101 102 86 wp_redirect(admin_url('plugins.php?deactivate=true')); 103 87 exit; 104 88 } 105 106 // Initialize the settings if they don't exist107 /*initialize_bulk_edit_settings();108 109 */110 89 function bulkedittoolkit_setup_post_type_specific_actions() { 111 90 $bulkedittoolkit_bulkEditSettings = bulkedittoolkit_BulkEditSettings::get_instance(); 112 91 $post_types = $bulkedittoolkit_bulkEditSettings->bulkedittoolkit_get_all_post_types(); 113 92 foreach ($post_types as $post_type) { 114 // quick edit115 93 add_action('save_post_' . $post_type, 'bulkedittoolkit_save_custom_bulk_edit'); 116 //add_action('save_post_' . $post_type, 'save_custom_quick_edit'); 117 // bulk actions 118 add_filter('bulk_actions-edit-' . $post_type, 'bulkedittoolkit_add_custom_bulk_actions'); 119 add_filter('handle_bulk_actions-edit-' . $post_type, 'bulkedittoolkit_handle_custom_bulk_action', 10, 3); 120 } 121 } 122 94 add_filter('bulk_actions-edit-' . $post_type, 'bulkedittoolkit_add_custom_bulk_actions'); 95 add_filter('handle_bulk_actions-edit-' . $post_type, 'bulkedittoolkit_handle_custom_bulk_action', 10, 3); 96 } 97 } 123 98 add_action('init', 'bulkedittoolkit_setup_post_type_specific_actions'); 124 // Mapping for field functions, might be moved or used in a different way125 // D'abord, vérifions s'il y a un post spécifique pour obtenir le post_type126 99 function bulkedittoolkit_get_current_post_type() { 127 100 global $post; 128 global $bulkedittoolkit_current_post_type; 129 101 global $bulkedittoolkit_current_post_type; 130 102 if (isset($post) && is_object($post)) { 131 103 return get_post_type($post->ID); 132 104 } 133 134 // Si $post n'est pas défini, peut-être qu'on est dans une situation où on peut obtenir le post_type d'une autre manière,135 // comme par la query string ou via l'URL.136 105 $post_type = filter_input(INPUT_GET, 'post_type', FILTER_UNSAFE_RAW); 137 106 if ($post_type) { 138 107 return $post_type; 139 108 } 140 141 // En dernier recours, on pourrait définir un type de post par défaut ou retourner null/false pour gérer différemment. 142 return 'post'; // ou return null; selon ce qui convient le mieux à votre logique. 143 } 144 145 // Ensuite, initialiser $field_function_map basé sur le post_type actuel pourrait être fait ici, 146 // mais dans votre cas, vous avez déjà une logique pour initialiser $field_function_map. 147 // Initialisation de la classe des paramètres de bulk edit 148 109 return 'post'; 110 } 149 111 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 150 151 112 $bulkedittoolkit_field_function_map = []; 152 153 113 foreach ($settings as $post_type => $fields) { 154 114 foreach ($fields as $field) { 155 // Chaque champ, peu importe son nom, pointera vers 'set_coming_soon'156 115 $bulkedittoolkit_field_function_map[$field['field_name']] = 'bulkedittoolkit_set_coming_soon'; 157 116 } 158 117 } 159 160 // Debug pour vérifier le contenu du $field_function_map161 // var_dump($field_function_map); // Décommentez pour le debuggage162 163 // Si vous voulez ajuster votre map basé sur le post_type, vous pourriez faire quelque chose comme :164 /*$base_field_function_map = [165 'coming_soon' => 'set_coming_soon',166 ];*/167 /*168 // Vous pouvez dynamiquement ajouter des entrées basées sur la base de données pour éviter la duplication manuelle169 170 // Récupérer toutes les settings pour les intégrer dans le mapping171 $bulk_edit_settings = BulkEditSettings::get_instance();172 $settings = $bulk_edit_settings->get_settings();173 174 foreach ($settings as $post_type => $fields) {175 foreach ($fields as $field) {176 // Vérifiez si le field_name n'est pas déjà dans le map pour éviter les doublons177 if (!isset($field_function_map[$field['field_name']])) {178 // Ici, vous pourriez créer une logique pour générer automatiquement des noms de fonctions179 // ou utiliser une fonction par défaut si aucune correspondance n'est définie180 $field_function_map[$field['field_name']] = 'set_' . sanitize_key($field['field_name']);181 }182 }183 }184 185 // $field_function_map contient maintenant des entrées basées sur la DB et votre mapping initial*/186 187 // Cette structure dépend de comment vous gérez les différents post_types.188 /*$field_function_map = $base_field_function_map;189 190 // Si vous avez des mappings spécifiques pour certains post_types:191 $post_type_specific_map = [192 'lp_course' => [193 'course_open' => 'set_course_open_status',194 ],195 // Ajoutez d'autres post_types ici.196 ];197 198 if (isset($post_type_specific_map[$current_post_type])) {199 $field_function_map = array_merge($field_function_map, $post_type_specific_map[$current_post_type]);200 }201 */202 // Maintenant $field_function_map a les mappings généraux plus ceux spécifiques au post_type courant.203 204 /*205 // This function would initialize the settings if none exist206 function initialize_bulk_edit_settings() {207 if (false == get_option('bulk_edit_settings')) {208 add_option('bulk_edit_settings', [209 'post_type' => 'lp_course',210 'field_name' => 'coming_soon',211 'input_type' => 'checkbox',212 ]);213 }214 debug_log("Bulk edit settings initialized or already present", $GLOBALS["is_debug_active"]);215 }216 217 $bulk_edit_settings = get_option('bulk_edit_settings', [218 'post_type' => 'lp_course',219 'field_name' => 'coming_soon',220 'input_type' => 'checkbox'221 ]);222 */223 224 118 function bulkedittoolkit_save_custom_bulk_edit($post_id) { // modification de masse via quick edit 225 119 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'])) { 122 bulkedittoolkit_debug_log("Posts in REQUEST: " . print_r($_REQUEST['post'], true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 123 } 226 124 //error_log("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); 227 125 // Vérifiez si c'est une autosave ou si le type de post ne correspond pas … … 229 127 return; 230 128 } 231 232 129 $all_post_types = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_all_post_types(); 233 234 130 if (!in_array(get_post_type($post_id), $all_post_types)) { 235 131 return; // Sortir si le type de post actuel n'est pas dans la liste des types de posts gérés 236 132 } 237 238 133 $fields_names = bulkedittoolkit_get_bulk_edit_field_name(get_post_type($post_id)); 239 240 134 // Traitement de la modification en masse 241 135 bulkedittoolkit_debug_log("before"); 242 136 if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'edit' && isset($_REQUEST['bulk_edit'])) { 243 bulkedittoolkit_debug_log("after");137 bulkedittoolkit_debug_log("after"); 244 138 // Sanitize and validate the array of post IDs 245 139 $posts_to_update = isset($_REQUEST['post']) ? (array)$_REQUEST['post'] : array(); … … 247 141 $posts_to_update = array_filter($posts_to_update); // Remove any potential falsy values (like 0 or empty strings) 248 142 foreach ($fields_names as $field_name => $field_details) { 249 bulkedittoolkit_debug_log("loop");250 bulkedittoolkit_debug_log($field_name);143 bulkedittoolkit_debug_log("loop"); 144 bulkedittoolkit_debug_log($field_name); 251 145 // Vérifie si ce champ spécifique est soumis dans la requête 252 146 $custom_field_key = 'custom_' . $field_name; 253 bulkedittoolkit_debug_log($custom_field_key); 254 if (isset($_REQUEST[$custom_field_key])) { 255 $value = sanitize_text_field($_REQUEST[$custom_field_key]); // 'yes' si coché, sinon la valeur soumise 256 } else { 257 // Si la clé n'est pas définie, cela signifie que la checkbox est décochée 258 $value = false; // ou false, selon ce que votre logique attend 259 } 260 261 bulkedittoolkit_debug_log($value); 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"]); 155 continue; 156 } 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 164 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"]); 167 } 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 } 172 bulkedittoolkit_debug_log("Value for $field_name: $value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 262 173 foreach ($posts_to_update as $post_id) { 263 174 // Supposant que set_coming_soon peut gérer différents champs ou que vous avez une fonction plus générique … … 269 180 return; // Sortir après avoir traité la modification en masse 270 181 } 271 if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) {182 if (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save" && isset($_REQUEST["post_ID"])) { 272 183 $post_id = intval($_REQUEST["post_ID"]); // Sanitize post ID 273 274 184 if (get_post($post_id)) { // Check if the post exists 275 185 bulkedittoolkit_save_custom_quick_edit($post_id); … … 281 191 } 282 192 } 283 284 285 } 286 287 // Assurez-vous de hooker la fonction correctement 288 //debug_log($current_post_type);debug_log("TTTTTTTTTTTTTTTTTTTTTTT"); 289 //add_action('save_post_' . $current_post_type, 'save_custom_bulk_edit'); 290 291 292 293 294 295 296 // Add custom column 193 } 297 194 function bulkedittoolkit_add_custom_columns($columns) { 298 195 global $bulkedittoolkit_bulk_edit_settings; 299 global $bulkedittoolkit_current_post_type;300 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); // Supposons que get_settings() retourne tous les settings pour le post_type actuel196 global $bulkedittoolkit_current_post_type; 197 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 301 198 if (isset($settings[$bulkedittoolkit_current_post_type])) { 302 199 foreach($settings[$bulkedittoolkit_current_post_type] as $setting) { 303 $columns[$setting['field_name']] = ucfirst(implode(' ', explode('_', $setting['field_name']))); // human readable mon q304 bulkedittoolkit_debug_log(" Added custom column: " . $setting['field_name'], $GLOBALS["bulkedittoolkit_is_debug_active"]);200 $columns[$setting['field_name']] = ucfirst(implode(' ', explode('_', $setting['field_name']))); 201 bulkedittoolkit_debug_log("GROKTRACE_ADD_COLUMN: Added custom column: " . $setting['field_name'], $GLOBALS["bulkedittoolkit_is_debug_active"]); 305 202 } 306 203 } … … 308 205 } 309 206 add_filter('manage_' . $bulkedittoolkit_current_post_type . '_posts_columns', 'bulkedittoolkit_add_custom_columns'); 310 311 // Display custom column data312 207 function bulkedittoolkit_display_custom_column_data($column, $post_id) { 313 208 global $bulkedittoolkit_bulk_edit_settings; 314 global $bulkedittoolkit_current_post_type; 315 316 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); // Récupérer tous les settings 209 global $bulkedittoolkit_current_post_type; 210 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_settings(); 317 211 if (isset($settings[$bulkedittoolkit_current_post_type])) { 318 212 foreach($settings[$bulkedittoolkit_current_post_type] as $setting) { 319 213 if ($column == $setting['field_name']) { 320 $meta_key = /*$current_post_type . '_' .*/$setting['field_name'];214 $meta_key = $setting['field_name']; 321 215 $status = get_post_meta($post_id, $meta_key, true); 322 323 // Affichage basé sur le type de l'input324 216 switch ($setting['input_type']) { 325 217 case 'checkbox': 326 echo $status && (strtolower($status) !== 'no' && strtolower($status) !== 0 && strtolower($status) !== false) ? 'Yes' : 'No'; // Pour les checkbox, on reste avec Yes/No218 echo $status && (strtolower($status) !== 'no' && strtolower($status) !== '0' && strtolower($status) !== 'false') ? 'Yes' : 'No'; 327 219 break; 328 220 case 'datetime': … … 331 223 break; 332 224 default: 333 echo esc_html($status); // Pour les autres types, afficher la valeur telle quelle, après échappement pour la sécurité225 echo esc_html($status); 334 226 } 335 336 bulkedittoolkit_debug_log("Displaying column data $post_id for $column with status: " . var_export($status, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 337 break; 338 bulkedittoolkit_debug_log("Displaying column data for $column with status: $status", $GLOBALS["bulkedittoolkit_is_debug_active"]); 339 break; // On sort de la boucle car on a trouvé notre colonne 227 bulkedittoolkit_debug_log("GROKTRACE_DISPLAY_COLUMN: Displaying column data $post_id for $column with status: " . var_export($status, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 340 228 } 341 229 } … … 343 231 } 344 232 add_action('manage_' . $bulkedittoolkit_current_post_type . '_posts_custom_column', 'bulkedittoolkit_display_custom_column_data', 10, 2); 345 346 347 348 // Here you would close your PHP file if there's no more code to add349 350 233 ?> -
bulk-content-toolkit/trunk/includes/admin/bulk-actions.php
r3188505 r3349434 6 6 global $bulkedittoolkit_bulk_edit_settings; 7 7 8 $bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); // Obtenir le type de post courant ou utiliser un moyen approprié pour le définir8 /*$bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); // Obtenir le type de post courant ou utiliser un moyen approprié pour le définir 9 9 10 10 if ($bulkedittoolkit_current_post_type) { 11 11 $fields = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_field_names_for_post_type($bulkedittoolkit_current_post_type); 12 12 13 13 foreach ($fields as $field_name) { 14 14 $action_name = bulkedittoolkit_get_coming_soon_action_name($field_name); // Assurez-vous que cette fonction existe pour formater le nom de l'action … … 16 16 bulkedittoolkit_debug_log("Added bulk action for field: " . $field_name, $GLOBALS["bulkedittoolkit_is_debug_active"]); 17 17 } 18 } 18 }*/ 19 19 20 20 return $bulk_actions; … … 27 27 function bulkedittoolkit_handle_custom_bulk_action($redirect_to, $doaction, $post_ids) { //select set coming soon on the left 28 28 global $bulkedittoolkit_bulk_edit_settings; 29 29 30 30 $bulkedittoolkit_current_post_type = bulkedittoolkit_get_current_post_type(); 31 31 32 32 if ($bulkedittoolkit_current_post_type) { 33 33 $fields = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_field_names_for_post_type($bulkedittoolkit_current_post_type); … … 50 50 if (!empty($_REQUEST['bulk_' . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name') . '_items'])) { 51 51 $count = intval($_REQUEST['bulk_' . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name') . '_items']); 52 printf('<div id="message" class="updated notice is-dismissible"><p>' . 53 esc_html( _n('%s item has been set to %s.', '%s items have been set to %s.', $count, 'bulk-content-toolkit') ) . 52 printf('<div id="message" class="updated notice is-dismissible"><p>' . 53 esc_html( _n('%s item has been set to %s.', '%s items have been set to %s.', $count, 'bulk-content-toolkit') ) . 54 54 '</p></div>', $count, esc_html( ucfirst($bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name')) ) ); 55 55 bulkedittoolkit_debug_log("$count items processed for setting: " . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name'), $GLOBALS["bulkedittoolkit_is_debug_active"]); -
bulk-content-toolkit/trunk/includes/admin/quick-edit.php
r3349071 r3349434 1 1 <?php 2 3 2 defined('ABSPATH') or die('PIF PAF POUF!'); 4 3 … … 15 14 global $bulkedittoolkit_bulk_edit_settings, $bulkedittoolkit_current_post_type; 16 15 $settings = $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting($bulkedittoolkit_current_post_type); 17 if (!isset($settings)) return; // acs des onglets catégorie - étiquette16 if (!isset($settings)) return; // acs des onglets catégorie - étiquette 18 17 $settings = array_column($settings, 'input_type', 'field_name'); 19 20 18 $html_generators = [ 21 19 'checkbox' => function($field_name, $context = '') { 22 return bulkedittoolkit_generate_switch_html($field_name, $context);23 },24 'switch' => function($field_name, $context = '') {25 return bulkedittoolkit_generate_switch_html($field_name, $context);26 },27 'select' => function($field_name, $context = '') {28 return bulkedittoolkit_generate_select_html($field_name, $context);29 },30 'text' => function($field_name, $context = '') {31 return bulkedittoolkit_generate_text_html($field_name, $context);32 },33 'number' => function($field_name, $context = '') {34 return bulkedittoolkit_generate_number_html($field_name, $context);35 },36 'datetime' => function($field_name, $context = '') {37 return bulkedittoolkit_generate_datetime_html($field_name, $context);38 },39 'radio' => function($field_name, $context = '') {40 return bulkedittoolkit_generate_radio_html($field_name, $context);41 },42 'textarea' => function($field_name, $context = '') {43 return bulkedittoolkit_generate_textarea_html($field_name, $context);44 },45 'file' => function($field_name, $context = '') {46 return bulkedittoolkit_generate_file_html($field_name, $context);47 },48 'email' => function($field_name, $context = '') {49 return bulkedittoolkit_generate_email_html($field_name, $context);50 },51 'password' => function($field_name, $context = '') {52 return bulkedittoolkit_generate_password_html($field_name, $context);53 },54 'url' => function($field_name, $context = '') {55 return bulkedittoolkit_generate_url_html($field_name, $context);56 },57 'color' => function($field_name, $context = '') {58 return bulkedittoolkit_generate_color_html($field_name, $context);59 },60 'range' => function($field_name, $context = '') {61 return bulkedittoolkit_generate_range_html($field_name, $context);62 },20 return bulkedittoolkit_generate_switch_html($field_name, $context); 21 }, 22 'switch' => function($field_name, $context = '') { 23 return bulkedittoolkit_generate_switch_html($field_name, $context); 24 }, 25 'select' => function($field_name, $context = '') { 26 return bulkedittoolkit_generate_select_html($field_name, $context); 27 }, 28 'text' => function($field_name, $context = '') { 29 return bulkedittoolkit_generate_text_html($field_name, $context); 30 }, 31 'number' => function($field_name, $context = '') { 32 return bulkedittoolkit_generate_number_html($field_name, $context); 33 }, 34 'datetime' => function($field_name, $context = '') { 35 return bulkedittoolkit_generate_datetime_html($field_name, $context); 36 }, 37 'radio' => function($field_name, $context = '') { 38 return bulkedittoolkit_generate_radio_html($field_name, $context); 39 }, 40 'textarea' => function($field_name, $context = '') { 41 return bulkedittoolkit_generate_textarea_html($field_name, $context); 42 }, 43 'file' => function($field_name, $context = '') { 44 return bulkedittoolkit_generate_file_html($field_name, $context); 45 }, 46 'email' => function($field_name, $context = '') { 47 return bulkedittoolkit_generate_email_html($field_name, $context); 48 }, 49 'password' => function($field_name, $context = '') { 50 return bulkedittoolkit_generate_password_html($field_name, $context); 51 }, 52 'url' => function($field_name, $context = '') { 53 return bulkedittoolkit_generate_url_html($field_name, $context); 54 }, 55 'color' => function($field_name, $context = '') { 56 return bulkedittoolkit_generate_color_html($field_name, $context); 57 }, 58 'range' => function($field_name, $context = '') { 59 return bulkedittoolkit_generate_range_html($field_name, $context); 60 }, 63 61 ]; 64 65 62 if (!isset($settings[$post_type])) return; 66 67 $allowed_html = array( 63 $allowed_html = array( 68 64 'fieldset' => array( 69 65 'class' => true, … … 74 70 'label' => array( 75 71 'for' => true, 72 'class' => true, 76 73 ), 77 74 'span' => array( … … 84 81 'value' => true, 85 82 'data-initial-state' => true, 86 ), 87 'select' => array( 83 'step' => true, 84 'min' => true, 85 'max' => true, 86 ), 87 'select' => array( 88 88 'name' => true, 89 89 'id' => true, 90 90 'aria-label' => true, 91 'class' => true, 91 92 ), 92 'option' => array( 93 'value' => true, 94 'selected' => true, 95 ), 93 'option' => array( 94 'value' => true, 95 'selected' => true, 96 ), 97 'textarea' => array( 98 'name' => true, 99 'id' => true, 100 'cols' => true, 101 'rows' => true, 102 ), 96 103 // Add other tags and attributes as needed 97 104 ); 98 99 105 echo wp_kses( bulkedittoolkit_generate_fieldset_start(), $allowed_html ); 100 106 echo wp_kses( bulkedittoolkit_generate_label($post_type, $context), $allowed_html ); 101 107 echo wp_kses( bulkedittoolkit_generate_input_wrapper($post_type, $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_input_type($bulkedittoolkit_current_post_type, $post_type), $html_generators, $context), $allowed_html ); 102 108 echo wp_kses( bulkedittoolkit_generate_fieldset_end(), $allowed_html ); 103 104 109 bulkedittoolkit_debug_log("Added bulk edit field for: " . $post_type, $GLOBALS["bulkedittoolkit_is_debug_active"]); 105 110 } … … 107 112 // Fonctions de génération de HTML 108 113 function bulkedittoolkit_generate_fieldset_start() { 109 // Génération du champ nonce pour la sécurité114 // Génération du champ nonce pour la sécurité 110 115 $nonce_html = wp_nonce_field('update_custom_fields_action', 'update_custom_fields_nonce', true, false); 111 112 116 // Début de la structure HTML pour l'édition en vrac 113 $html = '<fieldset class="inline-edit-col-right">' . 117 $html = '<fieldset class="inline-edit-col-right">' . 114 118 '<div class="inline-edit-col">' . 115 119 $nonce_html; 116 117 120 // Retour du HTML généré 118 121 return $html; 119 /*120 // Inside your function where you generate the HTML for the input or form122 /* 123 // Inside your function where you generate the HTML for the input or form 121 124 echo wp_nonce_field('update_custom_fields_action', 'update_custom_fields_nonce', true, false); 122 125 return '<fieldset class="inline-edit-col-right"><div class="inline-edit-col">';*/ … … 146 149 function bulkedittoolkit_generate_select_html($field_name, $context) { 147 150 global $wpdb, $post; 148 149 151 // Récupérer le post_id (soit via $post, soit via $_REQUEST pour la modification rapide) 150 152 $post_id = isset($post->ID) ? $post->ID : (isset($_REQUEST['post_ID']) ? intval($_REQUEST['post_ID']) : 0); 151 152 153 // Récupérer la valeur actuelle du champ pour ce post 153 154 $current_value = ''; … … 156 157 bulkedittoolkit_debug_log("Valeur actuelle pour $field_name (post_id $post_id) : " . $current_value, $GLOBALS["bulkedittoolkit_is_debug_active"]); 157 158 } 158 159 159 // Récupérer les valeurs distinctes pour le champ 160 160 $results = $wpdb->get_results( … … 165 165 ); 166 166 bulkedittoolkit_debug_log("Valeurs récupérées pour $field_name : " . print_r($results, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 167 168 167 // Créer le select 169 168 $html = '<select name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" aria-label="' . esc_attr__('Select value for ', 'bulk-content-toolkit') . esc_html($field_name) . '">'; 170 171 169 // Ajouter une option par défaut 172 $html .= '<option value=""' . ($current_value === '' ? ' selected' : '') . '>' . esc_html__('Select a value', 'bulk-content-toolkit') . '</option>'; 173 170 $html .= '<option value=""' . ($context === 'bulk' ? '' : ($current_value === '' ? ' selected' : '')) . '>' . ($context === 'bulk' ? esc_html__('— Aucun changement —', 'bulk-content-toolkit') : esc_html__('Select a value', 'bulk-content-toolkit')) . '</option>'; 174 171 // Ajouter les options 175 172 foreach ($results as $result) { … … 180 177 } 181 178 } 182 183 179 $html .= '</select>'; 184 185 180 // Débogage : enregistrer le HTML généré 186 181 bulkedittoolkit_debug_log("HTML généré pour $field_name : $html", $GLOBALS["bulkedittoolkit_is_debug_active"]); 187 188 182 return $html; 189 183 } 190 184 191 185 function bulkedittoolkit_get_value($field_name) { 192 global $wpdb, $post;186 global $wpdb, $post; 193 187 // il faut boucler ici car la valeur récupérée est celle du dernier post id 194 188 // Récupérer la valeur de la base de données pour le post et le champ donnés … … 197 191 $post->ID, $field_name 198 192 )); 199 200 return ($value); 193 return ($value); 201 194 } 202 195 203 196 function bulkedittoolkit_generate_text_html($field_name, $context = '') { 204 205 197 // Si aucune valeur n'est trouvée, $value sera NULL, donc on utilise une chaîne vide par défaut 206 $value = bulkedittoolkit_get_value($field_name) ?? ''; 207 208 return '<input type="text" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 198 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 199 $html = ''; 200 if ($context === 'bulk') { 201 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 202 $html .= '<option value="">— Aucun changement —</option>'; 203 $html .= '<option value="1">Changer pour :</option>'; 204 $html .= '</select>'; 205 $html .= '<label class="change-input" style="display: none;">'; 206 } 207 $html .= '<input type="text" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 208 if ($context === 'bulk') { 209 $html .= '</label>'; 210 } 211 return $html; 209 212 } 210 213 211 214 function bulkedittoolkit_generate_number_html($field_name, $context = '') { 212 213 $value = bulkedittoolkit_get_value($field_name) ?? ''; 214 215 return '<input type="number" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 216 //return '<input type="number" name="' . $field_name . '" id="' . $field_name . '"' . 217 // ($context ? ' data-context="' . htmlspecialchars($context) . '"' : '') . '>'; 215 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 216 $html = ''; 217 if ($context === 'bulk') { 218 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 219 $html .= '<option value="">— Aucun changement —</option>'; 220 $html .= '<option value="1">Changer pour :</option>'; 221 $html .= '</select>'; 222 $html .= '<label class="change-input" style="display: none;">'; 223 } 224 $html .= '<input type="number" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 225 if ($context === 'bulk') { 226 $html .= '</label>'; 227 } 228 //return '<input type="number" name="' . $field_name . '" id="' . $field_name . '"' . 229 // ($context ? ' data-context="' . htmlspecialchars($context) . '"' : '') . '>'; 230 return $html; 218 231 } 219 232 220 233 function bulkedittoolkit_generate_datetime_html($field_name, $context = '') { 221 222 $value = bulkedittoolkit_get_value($field_name) ?? ''; 223 234 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 224 235 // Génération de code HTML pour un sélecteur de date et heure 225 return '<input type="datetime-local" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 236 $html = ''; 237 if ($context === 'bulk') { 238 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 239 $html .= '<option value="">— Aucun changement —</option>'; 240 $html .= '<option value="1">Changer pour :</option>'; 241 $html .= '</select>'; 242 $html .= '<label class="change-input" style="display: none;">'; 243 } 244 $html .= '<input type="datetime-local" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 245 if ($context === 'bulk') { 246 $html .= '</label>'; 247 } 248 return $html; 226 249 } 227 250 228 251 function bulkedittoolkit_generate_radio_html($field_name, $context = '') { 229 230 $value = bulkedittoolkit_get_value($field_name) ?? ''; 231 252 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 232 253 // Générer du HTML pour des boutons radio, ici on suppose une version simplifiée 233 return '<input type="radio" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 254 $html = ''; 255 if ($context === 'bulk') { 256 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 257 $html .= '<option value="">— Aucun changement —</option>'; 258 $html .= '<option value="1">Changer pour :</option>'; 259 $html .= '</select>'; 260 $html .= '<label class="change-input" style="display: none;">'; 261 } 262 $html .= '<input type="radio" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 263 if ($context === 'bulk') { 264 $html .= '</label>'; 265 } 266 return $html; 234 267 } 235 268 236 269 function bulkedittoolkit_generate_textarea_html($field_name, $context = '') { 237 238 $value = bulkedittoolkit_get_value($field_name) ?? ''; 239 240 return '<textarea name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" /textarea>'; 270 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 271 $html = ''; 272 if ($context === 'bulk') { 273 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 274 $html .= '<option value="">— Aucun changement —</option>'; 275 $html .= '<option value="1">Changer pour :</option>'; 276 $html .= '</select>'; 277 $html .= '<label class="change-input" style="display: none;">'; 278 } 279 $html .= '<textarea name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" cols="22" rows="1">' . esc_textarea($value) . '</textarea>'; 280 if ($context === 'bulk') { 281 $html .= '</label>'; 282 } 283 return $html; 241 284 } 242 285 243 286 function bulkedittoolkit_generate_file_html($field_name, $context = '') { 244 245 $value = bulkedittoolkit_get_value($field_name) ?? ''; 246 247 return '<input type="file" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 287 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 288 $html = ''; 289 if ($context === 'bulk') { 290 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 291 $html .= '<option value="">— Aucun changement —</option>'; 292 $html .= '<option value="1">Changer pour :</option>'; 293 $html .= '</select>'; 294 $html .= '<label class="change-input" style="display: none;">'; 295 } 296 $html .= '<input type="file" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 297 if ($context === 'bulk') { 298 $html .= '</label>'; 299 } 300 return $html; 248 301 } 249 302 250 303 function bulkedittoolkit_generate_email_html($field_name, $context = '') { 251 252 $value = bulkedittoolkit_get_value($field_name) ?? ''; 253 254 return '<input type="email" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 304 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 305 $html = ''; 306 if ($context === 'bulk') { 307 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 308 $html .= '<option value="">— Aucun changement —</option>'; 309 $html .= '<option value="1">Changer pour :</option>'; 310 $html .= '</select>'; 311 $html .= '<label class="change-input" style="display: none;">'; 312 } 313 $html .= '<input type="email" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 314 if ($context === 'bulk') { 315 $html .= '</label>'; 316 } 317 return $html; 255 318 } 256 319 257 320 function bulkedittoolkit_generate_password_html($field_name, $context = '') { 258 259 $value = bulkedittoolkit_get_value($field_name) ?? ''; 260 261 return '<input type="password" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 321 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 322 $html = ''; 323 if ($context === 'bulk') { 324 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 325 $html .= '<option value="">— Aucun changement —</option>'; 326 $html .= '<option value="1">Changer pour :</option>'; 327 $html .= '</select>'; 328 $html .= '<label class="change-input" style="display: none;">'; 329 } 330 $html .= '<input type="password" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 331 if ($context === 'bulk') { 332 $html .= '</label>'; 333 } 334 return $html; 262 335 } 263 336 264 337 function bulkedittoolkit_generate_url_html($field_name, $context = '') { 265 266 $value = bulkedittoolkit_get_value($field_name) ?? ''; 267 268 return '<input type="url" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 338 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 339 $html = ''; 340 if ($context === 'bulk') { 341 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 342 $html .= '<option value="">— Aucun changement —</option>'; 343 $html .= '<option value="1">Changer pour :</option>'; 344 $html .= '</select>'; 345 $html .= '<label class="change-input" style="display: none;">'; 346 } 347 $html .= '<input type="url" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 348 if ($context === 'bulk') { 349 $html .= '</label>'; 350 } 351 return $html; 269 352 } 270 353 271 354 function bulkedittoolkit_generate_color_html($field_name, $context = '') { 272 273 $value = bulkedittoolkit_get_value($field_name) ?? ''; 274 275 return '<input type="color" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 355 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 356 $html = ''; 357 if ($context === 'bulk') { 358 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 359 $html .= '<option value="">— Aucun changement —</option>'; 360 $html .= '<option value="1">Changer pour :</option>'; 361 $html .= '</select>'; 362 $html .= '<label class="change-input" style="display: none;">'; 363 } 364 $html .= '<input type="color" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" value="' . esc_attr($value) . '" />'; 365 if ($context === 'bulk') { 366 $html .= '</label>'; 367 } 368 return $html; 276 369 } 277 370 278 371 function bulkedittoolkit_generate_range_html($field_name, $context = '') { 279 280 $value = bulkedittoolkit_get_value($field_name) ?? ''; 281 372 $value = $context === 'bulk' ? '' : (bulkedittoolkit_get_value($field_name) ?? ''); 282 373 // Ici, on doit définir un min, max, et step pour que le range fonctionne correctement 283 return '<input type="range" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" min="0" max="100" step="1"' . '" value="' . esc_attr($value) . '" />'; 374 $html = ''; 375 if ($context === 'bulk') { 376 $html .= '<select class="change_' . esc_attr($field_name) . ' change_to" name="change_custom_' . esc_attr($field_name) . '">'; 377 $html .= '<option value="">— Aucun changement —</option>'; 378 $html .= '<option value="1">Changer pour :</option>'; 379 $html .= '</select>'; 380 $html .= '<label class="change-input" style="display: none;">'; 381 } 382 $html .= '<input type="range" name="' . esc_attr('custom_' . $field_name) . '" id="bulk_edit_custom_' . esc_attr($field_name) . '_' . esc_attr($context) . '" min="0" max="100" step="1" value="' . esc_attr($value) . '" />'; 383 if ($context === 'bulk') { 384 $html .= '</label>'; 385 } 386 return $html; 284 387 } 285 388 … … 298 401 }, 10, 1); 299 402 300 // Save Quick Edit 403 // Save Quick Edit 301 404 function bulkedittoolkit_save_custom_quick_edit($post_id) { 302 405 global $bulkedittoolkit_bulk_edit_settings, $bulkedittoolkit_field_function_map; … … 314 417 continue; // Passe au champ suivant si la fonction n'est pas trouvée 315 418 } 316 317 419 // Récupérer le nom de la fonction mappée au nom du champ 318 420 $function_name = $bulkedittoolkit_field_function_map[$field_name]; 319 320 421 // Vérifier si la requête contient la valeur du champ et si elle est active 321 422 $request_key = "custom_" . $field_name;//get_bulk_edit_field_name($bulkedittoolkit_current_post_type);//$field_name); … … 336 437 //} 337 438 } 338 else {439 else { 339 440 call_user_func($function_name, $post_id, $field_name, false); 340 }441 } 341 442 } 342 443 } … … 349 450 // Vérification de nonce pour la sécurité 350 451 check_admin_referer('update_custom_fields_nonce'); 351 352 452 // Vérifier les permissions de l'utilisateur 353 453 if (!current_user_can('edit_posts')) { … … 357 457 if (isset($_POST['post_id'])) { 358 458 $post_id = intval($_POST['post_id']); // Sanitize post ID to ensure it's an integer 359 360 459 if (get_post($post_id)) { // Check if the post exists 361 460 foreach ($_POST as $key => $value) { -
bulk-content-toolkit/trunk/includes/core-functions.php
r3188505 r3349434 10 10 $message = print_r($message, true); 11 11 } 12 error_log( $message);12 error_log("[bct]:" . $message); 13 13 } 14 14 } -
bulk-content-toolkit/trunk/includes/utils/helpers.php
r3188505 r3349434 28 28 // Construit la clé de métadonnée avec un underscore au début si nécessaire 29 29 $meta_key = $field_name;//'_' . $prefix . $bulkedittoolkit_bulk_edit_settings->bulkedittoolkit_get_setting('field_name'); 30 30 $current_value = get_post_meta($post_id, $meta_key, true); 31 bulkedittoolkit_debug_log("Current value for $meta_key on post $post_id before update: $current_value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 31 32 // Met à jour la métadonnée du post 32 update_post_meta($post_id, $meta_key, $status); 33 33 $result = update_post_meta($post_id, $meta_key, $status); 34 bulkedittoolkit_debug_log("Update result for $meta_key on post $post_id with $status: " . var_export($result, true), $GLOBALS["bulkedittoolkit_is_debug_active"]); 35 $new_value = get_post_meta($post_id, $meta_key, true); 36 bulkedittoolkit_debug_log("New value for $meta_key on post $post_id after update: $new_value", $GLOBALS["bulkedittoolkit_is_debug_active"]); 34 37 bulkedittoolkit_debug_log("Setting {$meta_key} to {$status} for post ID {$post_id}", $GLOBALS["bulkedittoolkit_is_debug_active"]); 35 38 if ($all) { -
bulk-content-toolkit/trunk/js/bulk-edit-admin.js
r3188505 r3349434 1 1 document.addEventListener('DOMContentLoaded', function() { 2 // Gestion des champs <select> change_to pour les inputs et textareas (sauf checkboxes) 3 const changeToSelects = document.querySelectorAll('.change_to'); 4 changeToSelects.forEach(select => { 5 const fieldName = select.name.replace('change_custom_', 'custom_'); 6 const input = document.querySelector(`[name="${fieldName}"]`); 7 if (input && input.type !== 'checkbox') { 8 select.addEventListener('change', () => { 9 const inputLabel = input.closest('.change-input'); 10 if (select.value === '1') { 11 inputLabel.style.display = 'inline-block'; 12 } else { 13 inputLabel.style.display = 'none'; 14 input.value = ''; 15 } 16 }); 17 } 18 }); 19 20 // Le reste du fichier reste inchangé 2 21 const postTypeSelect = document.getElementById('post_type'); 3 22 const fieldNameContainer = document.getElementById('field-selection-container'); 4 5 23 function updateFields(postType) { 6 24 const data = { 7 25 action: 'update_fields_for_post_type', 8 26 post_type: postType, 9 nonce: bulkEditAdmin.nonce27 nonce: bulkEditAdmin.nonce 10 28 }; 11 12 fetch(ajaxurl, {13 method: 'POST',14 credentials: 'same-origin',15 headers: {16 'Content-Type': 'application/x-www-form-urlencoded',17 },18 body: new URLSearchParams(data).toString()19 })20 .then(response => response.json()) // Supposons que nous recevons un JSON avec les champs21 .then(data => {22 updateFieldSelection(data.fields, 0);23 })24 .catch(error => console.error('Error:', error));25 }26 27 function updateFieldSelection(fields, $available_or_selected) {28 const availableFieldsList = document.getElementById('available-fields').querySelector('ul');29 const selectFieldsList = document.getElementById('selected-fields').querySelector('ul');30 if ($available_or_selected === 0)31 availableFieldsList.innerHTML = ''; // Vider la liste actuelle32 else33 selectFieldsList.innerHTML = '';34 35 fields.forEach(field => {36 const li = document.createElement('li');37 li.textContent = field;38 li.dataset.field = field;39 if ($available_or_selected === 0)40 availableFieldsList.appendChild(li);41 else42 selectFieldsList.appendChild(li);43 });44 45 // Optionnel : Si vous voulez réinitialiser ou maintenir les champs sélectionnés46 //const selectedFieldsList = document.getElementById('selected-fields').querySelector('ul');47 //selectedFieldsList.innerHTML = ''; // Ou réinitialiser en fonction de la logique du backend48 }49 50 function loadSelectedFields(postType) {51 const data = {52 action: 'load_selected_fields',53 post_type: postType,54 nonce: bulkEditAdmin.nonce55 };56 57 29 fetch(ajaxurl, { 58 30 method: 'POST', … … 65 37 .then(response => response.json()) 66 38 .then(data => { 67 //const selectedFieldsList = document.getElementById('selected-fields').querySelector('ul'); 68 //selectedFieldsList.innerHTML = ''; 39 updateFieldSelection(data.fields, 0); 40 }) 41 .catch(error => console.error('Error:', error)); 42 } 43 function updateFieldSelection(fields, $available_or_selected) { 44 const availableFieldsList = document.getElementById('available-fields').querySelector('ul'); 45 const selectFieldsList = document.getElementById('selected-fields').querySelector('ul'); 46 if ($available_or_selected === 0) 47 availableFieldsList.innerHTML = ''; 48 else 49 selectFieldsList.innerHTML = ''; 50 fields.forEach(field => { 51 const li = document.createElement('li'); 52 li.textContent = field; 53 li.dataset.field = field; 54 if ($available_or_selected === 0) 55 availableFieldsList.appendChild(li); 56 else 57 selectFieldsList.appendChild(li); 58 }); 59 } 60 function loadSelectedFields(postType) { 61 const data = { 62 action: 'load_selected_fields', 63 post_type: postType, 64 nonce: bulkEditAdmin.nonce 65 }; 66 fetch(ajaxurl, { 67 method: 'POST', 68 credentials: 'same-origin', 69 headers: { 70 'Content-Type': 'application/x-www-form-urlencoded', 71 }, 72 body: new URLSearchParams(data).toString() 73 }) 74 .then(response => response.json()) 75 .then(data => { 69 76 if(data.fields) { 70 77 updateFieldSelection(data.fields, 1); … … 73 80 .catch(error => console.error('Error loading selected fields:', error)); 74 81 } 75 76 82 if(postTypeSelect && fieldNameContainer) { 77 83 postTypeSelect.addEventListener('change', function(e) { 78 loadSelectedFields(this.value);84 loadSelectedFields(this.value); 79 85 updateFields(this.value); 80 86 }); 81 loadSelectedFields(postTypeSelect.value); 82 // Trigger au chargement initial 87 loadSelectedFields(postTypeSelect.value); 83 88 updateFields(postTypeSelect.value); 84 85 // Logique pour bouger les champs ici ou dans une autre fonction si besoin86 89 document.querySelectorAll('.field-list ul').forEach(list => { 87 90 list.addEventListener('click', (e) => { … … 92 95 }); 93 96 } 94 95 // Définir ces variables après avoir assuré que le DOM est chargé et après avoir potentiellement modifié le contenu avec vos fonctions.96 const availableFields = document.getElementById('available-fields').querySelector('ul');97 const selectedFields = document.getElementById('selected-fields').querySelector('ul');98 99 97 function moveFields(direction) { 100 const availableFields = document.getElementById('available-fields').querySelector('ul'); 101 const selectedFields = document.getElementById('selected-fields').querySelector('ul'); 102 103 let fromList = direction === 'right' ? availableFields : selectedFields; 104 let toList = direction === 'right' ? selectedFields : availableFields; 105 106 Array.from(fromList.querySelectorAll('li.selected')).forEach(field => { 107 let fieldValue = field.dataset.field; 108 let alreadyExists = Array.from(toList.querySelectorAll('li')).some(existingField => existingField.dataset.field === fieldValue); 109 110 if (!alreadyExists || direction === 'left') { 111 field.classList.remove('selected'); 112 let newField = field.cloneNode(true); 113 if(direction === 'right') { 114 newField.innerHTML += '<input type="hidden" name="bulk_edit_settings[fields][]" value="' + fieldValue + '">'; 98 const availableFields = document.getElementById('available-fields').querySelector('ul'); 99 const selectedFields = document.getElementById('selected-fields').querySelector('ul'); 100 let fromList = direction === 'right' ? availableFields : selectedFields; 101 let toList = direction === 'right' ? selectedFields : availableFields; 102 Array.from(fromList.querySelectorAll('li.selected')).forEach(field => { 103 let fieldValue = field.dataset.field; 104 let alreadyExists = Array.from(toList.querySelectorAll('li')).some(existingField => existingField.dataset.field === fieldValue); 105 if (!alreadyExists || direction === 'left') { 106 field.classList.remove('selected'); 107 let newField = field.cloneNode(true); 108 if(direction === 'right') { 109 newField.innerHTML += '<input type="hidden" name="bulk_edit_settings[fields][]" value="' + fieldValue + '">'; 110 } 111 toList.appendChild(newField); 112 if(direction === 'left') { 113 field.remove(); 114 } 115 } else if(direction === 'right') { 116 console.log('Field already exists in selected list:', fieldValue); 115 117 } 116 toList.appendChild(newField); 117 if(direction === 'left') { 118 field.remove(); 118 }); 119 if(document.querySelector('#selected-fields ul li') !== null) { 120 saveFields(); 121 } else { 122 const postType = document.getElementById('post_type').value; 123 removePostTypeFromTable(postType); 124 } 125 } 126 function saveFields() { 127 const selectedFieldsList = document.querySelectorAll('#selected-fields ul li'); 128 const postType = document.getElementById('post_type').value; 129 const data = { 130 'action': 'bulk_edit_fields_save', 131 'post_type': postType, 132 'fields': Array.from(selectedFieldsList).map(li => li.dataset.field), 133 'nonce': bulkEditAdmin.nonce 134 }; 135 fetch(ajaxurl, { 136 method: 'POST', 137 credentials: 'same-origin', 138 headers: { 139 'Content-Type': 'application/x-www-form-urlencoded', 140 }, 141 body: new URLSearchParams(data).toString() 142 }) 143 .then(response => response.json()) 144 .then(response => { 145 const banner = document.createElement('div'); 146 banner.style.cssText = ` 147 position: fixed; 148 top: ${window.adminbar ? '64px' : '32px'}; 149 left: 0; 150 right: 0; 151 text-align: center; 152 background-color: ${response.success ? 'green' : 'red'}; 153 color: white; 154 padding: 10px; 155 z-index: 1000; 156 `; 157 banner.textContent = response.success ? 'Sauvegarde Ok' : 'Contenu identique déjà existant'; 158 document.body.appendChild(banner); 159 setTimeout(() => { 160 document.body.removeChild(banner); 161 }, 3000); 162 }) 163 .catch(error => { 164 console.error('Error saving fields:', error); 165 }); 166 } 167 function removePostTypeFromTable(postType) { 168 const nonce = document.querySelector('#bulk_edit_nonce').value; 169 const data = { 170 action: 'remove_post_type_from_bulk_edit', 171 post_type: postType, 172 nonce: nonce 173 }; 174 fetch(ajaxurl, { 175 method: 'POST', 176 credentials: 'same-origin', 177 headers: { 178 'Content-Type': 'application/x-www-form-urlencoded', 179 }, 180 body: new URLSearchParams(data).toString() 181 }) 182 .then(response => response.json()) 183 .then(response => { 184 if(response.success) { 185 console.log('Post type removed from bulk edit settings:', postType); 186 } else { 187 console.error('Failed to remove post type:', response.message); 119 188 } 120 } else if(direction === 'right') { 121 console.log('Field already exists in selected list:', fieldValue); 122 } 123 }); 124 125 if(document.querySelector('#selected-fields ul li') !== null) { 126 saveFields(); 189 }) 190 .catch(error => console.error('Error removing post type:', error)); 127 191 } 128 else {129 const postType = document.getElementById('post_type').value;130 // Logique pour supprimer le post_type de la table s'il n'a pas de champs sélectionnés131 removePostTypeFromTable(postType);132 }133 }134 135 function saveFields() {136 const selectedFieldsList = document.querySelectorAll('#selected-fields ul li');137 const postType = document.getElementById('post_type').value;138 const data = {139 'action': 'bulk_edit_fields_save',140 'post_type': postType,141 'fields': Array.from(selectedFieldsList).map(li => li.dataset.field),142 'nonce': bulkEditAdmin.nonce143 };144 145 fetch(ajaxurl, {146 method: 'POST',147 credentials: 'same-origin',148 headers: {149 'Content-Type': 'application/x-www-form-urlencoded',150 },151 body: new URLSearchParams(data).toString()152 })153 .then(response => response.json())154 .then(response => {155 const banner = document.createElement('div');156 banner.style.cssText = `157 position: fixed;158 top: ${window.adminbar ? '64px' : '32px'}; /* 32px est la hauteur de la barre admin en mode desktop */159 left: 0;160 right: 0;161 text-align: center;162 background-color: ${response.success ? 'green' : 'red'};163 color: white;164 padding: 10px;165 z-index: 1000;166 `;167 banner.textContent = response.success ? 'Sauvegarde Ok' : 'Contenu identique déjà existant';168 document.body.appendChild(banner);169 170 setTimeout(() => {171 document.body.removeChild(banner);172 }, 3000);173 })174 .catch(error => {175 console.error('Error saving fields:', error);176 });177 }178 179 function removePostTypeFromTable(postType) {180 // Récupérer le nonce généré par WordPress181 const nonce = document.querySelector('#bulk_edit_nonce').value; // Assurez-vous que ce champ ou un moyen similaire existe pour obtenir le nonce182 const data = {183 action: 'remove_post_type_from_bulk_edit',184 post_type: postType,185 nonce: nonce186 };187 188 fetch(ajaxurl, {189 method: 'POST',190 credentials: 'same-origin',191 headers: {192 'Content-Type': 'application/x-www-form-urlencoded',193 },194 body: new URLSearchParams(data).toString()195 })196 .then(response => response.json())197 .then(response => {198 if(response.success) {199 console.log('Post type removed from bulk edit settings:', postType);200 // Peut-être mettre à jour l'UI pour refléter le changement201 } else {202 console.error('Failed to remove post type:', response.message);203 }204 })205 .catch(error => console.error('Error removing post type:', error));206 }207 /*208 // Et assurez-vous que l'événement est attaché comme suit:209 document.querySelectorAll('.arrow-btn').forEach(button => {210 button.addEventListener('click', function(event) {211 event.preventDefault();212 const direction = this.dataset.direction;213 moveFields(direction);214 });215 });216 */217 // Attachement des événements aux boutons de flèche218 192 document.querySelectorAll('.arrow-btn').forEach(button => { 219 193 button.addEventListener('click', function(event) { -
bulk-content-toolkit/trunk/js/user.js
r3349071 r3349434 1 1 jQuery(document).ready(function($) { 2 // Surveiller l'apparition du formulaire Bulk Edit 3 const observer = new MutationObserver((mutations, observer) => { 4 mutations.forEach(mutation => { 5 if (mutation.addedNodes.length) { 6 const bulkForm = document.querySelector('.bulk-edit-row'); 7 if (bulkForm) { 8 // Formulaire trouvé, exécuter la logique 9 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 10 if (typeof bulkEditFieldNames === 'string') { 11 bulkEditFieldNames = {default: bulkEditFieldNames}; 12 } 13 const bulkItems = document.querySelectorAll('.ntdelitem button[id^="_"]'); 14 if (bulkItems.length === 0) return; 15 let postIds = Array.from(bulkItems).map(button => button.id.slice(1)); 16 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 17 // Ignorer _edit_lock 18 if (fieldName === '_edit_lock') { 19 console.log('Skipping _edit_lock to prevent interference'); 20 return; 21 } 22 const bulkEditId = `bulk_edit_${fieldName}_bulk`; 23 const bulkEditSwitch = document.querySelector('#' + bulkEditId + '[type="checkbox"]'); 24 const bulkEditInput = document.querySelector('#' + bulkEditId + ':not([type="checkbox"])'); 25 if (bulkEditSwitch) { 26 $.ajax({ 27 type: 'POST', 28 url: UserScriptParams.ajaxUrl, 29 data: { 30 action: 'get_bulk_edit_statuses', 31 post_ids: postIds, 32 field_name: fieldName, 33 nonce: UserScriptParams.nonce 34 }, 35 success: function(response) { 36 if (response.success) { 37 let allYes = true, allNo = true; 38 response.data.forEach(status => { 39 if (status !== 'yes' && status !== '1' && status !== true) allYes = false; 40 if (status !== 'no' && status !== '' && status !== false) allNo = false; 41 }); 42 if (allYes) { 43 bulkEditSwitch.indeterminate = false; 44 bulkEditSwitch.checked = true; 45 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 46 bulkEditSwitch.setAttribute('value', 'yes'); 47 bulkEditSwitch.removeAttribute('data-indeterminate'); 48 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 49 } else if (allNo) { 50 bulkEditSwitch.indeterminate = false; 51 bulkEditSwitch.checked = false; 52 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 53 bulkEditSwitch.setAttribute('value', 'no'); 54 bulkEditSwitch.removeAttribute('data-indeterminate'); 55 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 56 } else { 57 bulkEditSwitch.indeterminate = true; 58 bulkEditSwitch.checked = false; 59 bulkEditSwitch.removeAttribute('name'); 60 bulkEditSwitch.setAttribute('data-indeterminate', 'true'); 61 bulkEditSwitch.parentNode.classList.add('indeterminate'); 62 } 63 } else { 64 console.log('Failed to get statuses for field:', fieldName); 65 } 66 }, 67 error: function(error) { 68 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 69 } 70 }); 71 } else if (bulkEditInput) { 72 $.ajax({ 73 type: 'POST', 74 url: UserScriptParams.ajaxUrl, 75 data: { 76 action: 'get_bulk_edit_statuses', 77 post_ids: postIds, 78 field_name: fieldName, 79 nonce: UserScriptParams.nonce 80 }, 81 success: function(response) { 82 if (response.success) { 83 let allSame = true; 84 let firstValue = response.data[0]; 85 response.data.forEach(status => { 86 if (status !== firstValue) allSame = false; 87 }); 88 if (allSame && firstValue !== '' && firstValue !== null && firstValue !== false) { 89 bulkEditInput.value = firstValue; 90 } else { 91 bulkEditInput.value = ''; 92 } 93 } else { 94 console.log('Failed to get statuses for field:', fieldName); 95 } 96 }, 97 error: function(error) { 98 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 99 } 100 }); 101 } else { 102 console.log(`Field ${fieldName} not found as switch or input.`); 103 } 104 /*// Forcer _manage_stock à 'yes' si _stock est modifié 105 if (fieldName === '_stock') { 106 const manageStockSwitch = document.querySelector('#bulk_edit_custom__manage_stock_bulk[type="checkbox"]'); 107 if (manageStockSwitch && bulkEditInput && bulkEditInput.value !== '') { 108 manageStockSwitch.indeterminate = false; 109 manageStockSwitch.checked = true; 110 manageStockSwitch.setAttribute('name', 'custom__manage_stock'); 111 manageStockSwitch.setAttribute('value', 'yes'); 112 manageStockSwitch.removeAttribute('data-indeterminate'); 113 manageStockSwitch.parentNode.classList.remove('indeterminate'); 114 // Afficher le champ _stock 115 const stockField = document.querySelector('.stock_qty_field'); 116 if (stockField) stockField.style.display = 'block'; 117 } 118 }*/ 119 }); 120 // Arrêter l'observation une fois le formulaire traité 121 observer.disconnect(); 122 } 123 } 124 }); 125 }); 126 127 // Lancer l'observation sur le conteneur parent 128 observer.observe(document.body, { 129 childList: true, 130 subtree: true 131 }); 132 133 // Gérer le Quick Edit pour charger les valeurs correctes 2 134 $(document).on('click', '.editinline', function() { 3 135 var post_id = $(this).closest('tr').attr('id').replace("post-", ""); 4 136 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 5 137 if (typeof bulkEditFieldNames === 'string') { 138 bulkEditFieldNames = {default: bulkEditFieldNames}; 139 } 140 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 141 if (fieldName === '_edit_lock') return; 142 $.ajax({ 143 url: UserScriptParams.ajaxUrl, 144 type: 'POST', 145 data: { 146 action: 'get_quick_edit_status', 147 post_id: post_id, 148 field_name: key, 149 nonce: UserScriptParams.nonce 150 }, 151 success: function(response) { 152 var selector = '#edit-' + post_id + ' [name="custom_' + fieldName + '"]'; 153 var $element = $(selector); 154 if ($element.is(':checkbox')) { 155 $element.prop('checked', response === 'yes' || response == 1 || response === true || response === '1'); 156 $element.removeAttr('data-indeterminate'); 157 $element.parent().removeClass('indeterminate'); 158 } else { 159 $element.val(response); 160 } 161 // Afficher le champ _stock si _manage_stock est coché 162 if (fieldName === '_manage_stock' && (response === 'yes' || response == 1 || response === true || response === '1')) { 163 const stockField = document.querySelector('#edit-' + post_id + ' .stock_qty_field'); 164 if (stockField) stockField.style.display = 'block'; 165 } 166 }, 167 error: function(error) { 168 console.log('Error fetching quick edit status for field ' + key + ':', error); 169 } 170 }); 171 }); 172 }); 173 }); 174 175 176 /*jQuery(document).ready(function($) { 177 $(document).on('click', '.editinline', function() { 178 var post_id = $(this).closest('tr').attr('id').replace("post-", ""); 179 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 6 180 if (typeof bulkEditFieldNames === 'string') { 7 181 bulkEditFieldNames = {default: bulkEditFieldNames}; // Convertir en objet si c'est un string 8 182 } 9 10 183 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 11 184 $.ajax({ … … 16 189 'post_id': post_id, 17 190 'field_name': key, // Utilise la clé comme nom du champ pour l'ajax 18 'nonce': UserScriptParams.nonce // Ajouter le nonce pour la sécurité191 'nonce': UserScriptParams.nonce // Ajouter le nonce pour la sécurité 19 192 }, 20 193 success: function(response) { 21 //var checkedState = (response /*.data*/ === 'yes' || response === 1 || response === true); // Supposons que 'response' maintenant contient 'data'22 // Corriger le sélecteur pour cibler <input> ou <select>23 194 var selector = '#edit-' + post_id + ' [name="' + fieldName + '"]'; 24 //var selector = '#edit-' + post_id + ' input[name="' + fieldName + '"]'; 25 var $element = $(selector); //console.log($element);console.log("sdfghj"); 26 195 var $element = $(selector); 27 196 if ($element.is(':checkbox')) { 28 $element.prop('checked', response === 'yes' || response == 1 || response === true ); // Notez l'utilisation de '==' pour la comparaison loose197 $element.prop('checked', response === 'yes' || response == 1 || response === true || response === '1'); 29 198 } else if ($element.is('select')) { 30 //console.log("RESPONSE for " + fieldName + " (post_id " + post_id + "): ", response);31 // Gérer à la fois une réponse brute et une réponse structurée32 199 var value = typeof response === 'string' ? response : 33 200 (response && response.data && response.data[fieldName.replace('custom_', '')] && … … 35 202 response.data[fieldName.replace('custom_', '')].value : ''); 36 203 $element.val(value); 37 ///console.log("Valeur appliquée pour " + fieldName + ": ", value); 38 } else { // Par défaut, on suppose que c'est un input text 204 } else { 39 205 $element.val(response); 40 206 } 41 //$(selector).prop('checked', checkedState);42 207 }, 43 208 error: function(error) { … … 51 216 document.addEventListener('click', function(event) { 52 217 if (event.target.matches('.bulkactions #doaction, .bulkactions #doaction2')) { 53 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 54 218 var bulkEditFieldNames = UserScriptParams.bulkEditFieldNames; 55 219 if (typeof bulkEditFieldNames === 'string') { 56 220 bulkEditFieldNames = {default: bulkEditFieldNames}; // Convertir en objet si c'est un string 57 221 } 58 59 setTimeout(function() { 222 function() { 60 223 const bulkItems = document.querySelectorAll('.ntdelitem button[id^="_"]'); 61 224 if (bulkItems.length === 0) return; 62 63 225 let postIds = Array.from(bulkItems).map(button => button.id.slice(1)); 64 65 226 Object.entries(bulkEditFieldNames).forEach(([key, fieldName]) => { 66 227 const bulkEditId = `bulk_edit_${fieldName}_bulk`; 67 const bulkEditSwitch = document.querySelector('#' + bulkEditId); 228 const bulkEditSwitch = document.querySelector('#' + bulkEditId + '[type="checkbox"]'); 229 const bulkEditSelect = document.querySelector('#' + bulkEditId + '[type="select"]'); 68 230 69 231 if (bulkEditSwitch) { 232 // Handle checkbox fields 70 233 jQuery.ajax({ 71 234 type: 'POST', … … 75 238 post_ids: postIds, 76 239 field_name: fieldName, 77 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité240 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité 78 241 }, 79 242 success: function(response) { 80 243 if (response.success) { 81 244 let allYes = true, allNo = true; 82 83 245 response.data.forEach(status => { 84 if (status !== 'yes' ) allYes = false;85 if (status !== 'no' ) allNo = false;246 if (status !== 'yes' && status !== '1' && status !== true) allYes = false; 247 if (status !== 'no' && status !== '' && status !== false) allNo = false; 86 248 }); 87 88 249 if (allYes) { 89 250 bulkEditSwitch.indeterminate = false; 90 251 bulkEditSwitch.checked = true; 252 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 253 bulkEditSwitch.setAttribute('value', 'yes'); 254 bulkEditSwitch.removeAttribute('data-indeterminate'); 255 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 91 256 } else if (allNo) { 92 257 bulkEditSwitch.indeterminate = false; 93 258 bulkEditSwitch.checked = false; 259 bulkEditSwitch.setAttribute('name', 'custom_' + fieldName); 260 bulkEditSwitch.setAttribute('value', 'no'); 261 bulkEditSwitch.removeAttribute('data-indeterminate'); 262 bulkEditSwitch.parentNode.classList.remove('indeterminate'); 94 263 } else { 95 264 bulkEditSwitch.indeterminate = true; 96 265 bulkEditSwitch.checked = false; 266 bulkEditSwitch.removeAttribute('name'); 267 bulkEditSwitch.setAttribute('data-indeterminate', 'true'); 268 bulkEditSwitch.parentNode.classList.add('indeterminate'); 269 } 270 } else { 271 console.log('Failed to get statuses for field:', fieldName); 272 } 273 }, 274 error: function(error) { 275 console.log(`Error fetching bulk edit statuses for ${fieldName}:`, error); 276 } 277 }); 278 } else if (bulkEditSelect) { 279 // Handle select fields 280 jQuery.ajax({ 281 type: 'POST', 282 url: UserScriptParams.ajaxUrl, 283 data: { 284 action: 'get_bulk_edit_statuses', 285 post_ids: postIds, 286 field_name: fieldName, 287 nonce: UserScriptParams.nonce // Ajouter le nonce pour la sécurité 288 }, 289 success: function(response) { 290 if (response.success) { 291 // Check if all posts have the same value 292 let allSame = true; 293 let firstValue = response.data[0]; 294 response.data.forEach(status => { 295 if (status !== firstValue) allSame = false; 296 }); 297 if (allSame && firstValue !== '' && firstValue !== null && firstValue !== false) { 298 // If all posts have the same non-empty value, select it 299 bulkEditSelect.value = firstValue; 300 } else { 301 // Otherwise, select "— Aucun changement —" (empty value) 302 bulkEditSelect.value = ''; 97 303 } 98 304 } else { … … 105 311 }); 106 312 } else { 107 console.log(` Switch for ${fieldName} not found.`);313 console.log(`Field ${fieldName} not found as switch or select.`); 108 314 } 109 315 }); 110 } , 100);316 }; 111 317 } 318 });*/ 319 320 // Add event listener for checkbox toggle on slider click 321 /*document.addEventListener('DOMContentLoaded', function() { 322 document.querySelectorAll('.bulk-edit-checkbox .slider').forEach(slider => { 323 slider.addEventListener('click', function(event) { 324 const checkbox = this.previousElementSibling; // Get the checkbox input 325 if (checkbox && checkbox.type === 'checkbox') { 326 checkbox.checked = !checkbox.checked; // Toggle the checkbox state 327 checkbox.indeterminate = false; // Clear indeterminate state 328 checkbox.removeAttribute('data-indeterminate'); // Clear indeterminate tracking 329 checkbox.parentNode.classList.remove('indeterminate'); 330 // Ensure correct form submission behavior 331 if (checkbox.checked) { 332 checkbox.setAttribute('name', 'custom_' + checkbox.id.replace('bulk_edit_custom_', '').replace('_bulk', '')); 333 checkbox.setAttribute('value', 'yes'); 334 } else { 335 checkbox.setAttribute('name', 'custom_' + checkbox.id.replace('bulk_edit_custom_', '').replace('_bulk', '')); 336 checkbox.setAttribute('value', 'no'); // Explicitly send 'no' for unchecked 337 } 338 } 339 }); 340 }); 112 341 }); 342 */ -
bulk-content-toolkit/trunk/readme.txt
r3349072 r3349434 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.4 8 Stable Tag: 1.2. 18 Stable Tag: 1.2.2 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 46 46 47 47 == Changelog == 48 49 = 1.2.2 = 50 - **Improved: Clearer Bulk Interface. The goal is to Bulk Edit right ? 48 51 49 52 = 1.2.1 =
Note: See TracChangeset
for help on using the changeset viewer.