Make WordPress Core

Ticket #63005: 63005.alternative.diff

File 63005.alternative.diff, 2.9 KB (added by kabir93, 11 months ago)

Attached 63005.alternative.diff as an alternative approach. This patch: - Adds a filterable bulk_edit_input_name in WP_Users_List_Table with a context parameter for flexibility. - Localizes the input name to BulkEditSettings in user.js, keeping the solution specific to the Users screen. - Avoids modifying common.js, reducing the risk of side effects on other list tables. Compared to 63005.diff, this offers a more targeted fix, simpler maintenance, and a reusable filter design. It assumes a follow-up change in user.js to use BulkEditSettings.inputName (not included here but can be provided). Feedback welcome!

  • src/wp-admin/includes/class-wp-users-list-table.php

    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 { 
    5555                if ( $this->is_site_users ) {
    5656                        $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
    5757                }
     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                } );
    5872        }
    5973
    6074        /**
    class WP_Users_List_Table extends WP_List_Table { 
    300314        protected function extra_tablenav( $which ) {
    301315                $id        = 'bottom' === $which ? 'new_role2' : 'new_role';
    302316                $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                );
    303331                ?>
    304332        <div class="alignleft actions">
    305333                <?php if ( current_user_can( 'promote_users' ) && $this->has_items() ) : ?>
    class WP_Users_List_Table extends WP_List_Table { 
    309337                        _e( 'Change role to&hellip;' );
    310338                        ?>
    311339                </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; ?>">
    313341                        <option value=""><?php _e( 'Change role to&hellip;' ); ?></option>
    314342                        <?php wp_dropdown_roles(); ?>
    315343                        <option value="none"><?php _e( '&mdash; No role for this site &mdash;' ); ?></option>