Skip to content

Commit c38f581

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60186 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ab5d9e3 commit c38f581

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/js/_enqueues/admin/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ $( function() {
13271327

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 ) ) {
13341334
return;

src/wp-includes/script-loader.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,28 @@ function wp_default_scripts( $scripts ) {
757757
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils', 'wp-a11y' ), false, 1 );
758758
$scripts->set_translations( 'common' );
759759

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+
);
781+
760782
$scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
761783

762784
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );

0 commit comments

Comments
 (0)