Make WordPress Core

Changeset 60186 for trunk


Ignore:
Timestamp:
04/25/2025 06:19:01 PM (15 months ago)
Author:
joedolson
Message:

Themes: Add filter on bulk action fields.

Because validation was added in [59134] to prevent submitting bulk actions with no selected action, sites that remove or change the default bulk actions can fail due to the missing required inputs. Add a filter (bulk_action_observer_ids) that allows modifying the actions accepted to fulfill validation rules.

Props ethitter, kabir93, jorbin, davidbaumwald, joedolson.
Fixes #63005.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r59988 r60186  
    13281328                // Observe submissions from posts lists for 'bulk_action' or users lists for 'new_role'.
    13291329                var bulkFieldRelations = {
    1330                         'bulk_action' : 'action',
    1331                         'changeit' : 'new_role'
     1330                        'bulk_action' : window.bulkActionObserverIds.bulk_action,
     1331                        'changeit' : window.bulkActionObserverIds.changeit
    13321332                };
    13331333                if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) {
  • trunk/src/wp-includes/script-loader.php

    r59980 r60186  
    757757        $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils', 'wp-a11y' ), false, 1 );
    758758        $scripts->set_translations( 'common' );
     759
     760        $bulk_action_observer_ids = array(
     761                'bulk_action' => 'action',
     762                'changeit'    => 'new_role',
     763        );
     764        did_action( 'init' ) && $scripts->localize(
     765                'common',
     766                'bulkActionObserverIds',
     767                /**
     768                 * Filters the array of field name attributes for bulk actions.
     769                 *
     770                 * @since 6.8.1
     771                 *
     772                 * @param array $bulk_action_observer_ids {
     773                 *      An array of field name attributes for bulk actions.
     774                 *
     775                 *      @type string $bulk_action The bulk action field name. Default 'action'.
     776                 *      @type string $changeit    The new role field name. Default 'new_role'.
     777                 * }
     778                 */
     779                apply_filters( 'bulk_action_observer_ids', $bulk_action_observer_ids )
     780        );
    759781
    760782        $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.