From 03d84d4595e3cd2587fe20dace14e2246558f57f Mon Sep 17 00:00:00 2001
From: kabir-coderex <kabir@coderex.co>
Date: Mon, 24 Feb 2025 11:21:37 +0600
Subject: [PATCH] Fix #63005: Make bulk edit input name filterable
---
.../includes/class-wp-users-list-table.php | 30 ++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/wp-admin/includes/class-wp-users-list-table.php b/src/wp-admin/includes/class-wp-users-list-table.php
index 8dfe3ce1a3..bdf53065d2 100644
|
a
|
b
|
class WP_Users_List_Table extends WP_List_Table { |
| 55 | 55 | if ( $this->is_site_users ) { |
| 56 | 56 | $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0; |
| 57 | 57 | } |
| | 58 | |
| | 59 | // Hook into 'admin_enqueue_scripts' to conditionally load the 'users' script on user management pages. |
| | 60 | // This ensures 'user.js' is available for bulk edit enhancements and localization data, such as the dynamic input name. |
| | 61 | add_action( 'admin_enqueue_scripts', function( $hook ) { |
| | 62 | if ( 'users.php' === $hook || 'site-users.php' === $hook ) { |
| | 63 | wp_enqueue_script( |
| | 64 | 'users', |
| | 65 | admin_url( 'js/user.js' ), |
| | 66 | array( 'jquery' ), // Dependency on jQuery, required for existing functionality in user.js. |
| | 67 | false, // Version is omitted to use WordPress default or filemtime in development. |
| | 68 | true // Load in footer to ensure DOM is ready for script execution. |
| | 69 | ); |
| | 70 | } |
| | 71 | } ); |
| 58 | 72 | } |
| 59 | 73 | |
| 60 | 74 | /** |
| … |
… |
class WP_Users_List_Table extends WP_List_Table { |
| 300 | 314 | protected function extra_tablenav( $which ) { |
| 301 | 315 | $id = 'bottom' === $which ? 'new_role2' : 'new_role'; |
| 302 | 316 | $button_id = 'bottom' === $which ? 'changeit2' : 'changeit'; |
| | 317 | |
| | 318 | // Allow the bulk edit input name (e.g., 'new_role') to be customized via a filter. |
| | 319 | // This supports flexibility in bulk action forms, addressing ticket #63005. |
| | 320 | $bulk_input_name = apply_filters( 'bulk_edit_input_name', $id, 'users' ); |
| | 321 | |
| | 322 | // Pass the filtered input name to JavaScript for dynamic validation in user.js. |
| | 323 | // Uses 'users' script handle, enqueued separately, to ensure compatibility with bulk edit UI. |
| | 324 | wp_localize_script( |
| | 325 | 'users', |
| | 326 | 'BulkEditSettings', |
| | 327 | array( |
| | 328 | 'inputName' => $bulk_input_name, |
| | 329 | ) |
| | 330 | ); |
| 303 | 331 | ?> |
| 304 | 332 | <div class="alignleft actions"> |
| 305 | 333 | <?php if ( current_user_can( 'promote_users' ) && $this->has_items() ) : ?> |
| … |
… |
class WP_Users_List_Table extends WP_List_Table { |
| 309 | 337 | _e( 'Change role to…' ); |
| 310 | 338 | ?> |
| 311 | 339 | </label> |
| 312 | | <select name="<?php echo $id; ?>" id="<?php echo $id; ?>"> |
| | 340 | <select name="<?php echo esc_attr( $bulk_input_name ); ?>" id="<?php echo $id; ?>"> |
| 313 | 341 | <option value=""><?php _e( 'Change role to…' ); ?></option> |
| 314 | 342 | <?php wp_dropdown_roles(); ?> |
| 315 | 343 | <option value="none"><?php _e( '— No role for this site —' ); ?></option> |