Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/js/_enqueues/admin/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,53 @@ $( function() {
'bulk_action' : window.bulkActionObserverIds.bulk_action,
'changeit' : window.bulkActionObserverIds.changeit
};
if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) {

var filterButtonNames = [
window.bulkActionObserverIds.filter_action,
window.bulkActionObserverIds['post-query-submit']
];

if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) && ! filterButtonNames.includes( submitterName ) ) {
return;
}

if ( filterButtonNames.includes( submitterName ) ) {
var filterDropdowns = form.querySelectorAll( '.actions select' );
var isFilterActionValid = false;
var urlParams = new URLSearchParams( window.location.search );

for ( var i = 0; i < filterDropdowns.length; i++ ) {
var select = filterDropdowns[ i ];
if ( select.name === 'action' || select.name === 'action2' ) {
continue;
}
if ( select.value !== '0' && select.value !== '' && select.value !== '-1' ) {
isFilterActionValid = true;
break;
}
if ( urlParams.has( select.name ) ) {
isFilterActionValid = true;
break;
}
}

if ( isFilterActionValid ) {
return;
}

event.preventDefault();
event.stopPropagation();
$( 'html, body' ).animate( { scrollTop: 0 } );

var filterErrorMessage = __( 'Please select a filter to apply.' );
addAdminNotice( {
id: 'no-filter-selected',
type: 'error',
message: filterErrorMessage,
dismissible: true,
} );

wp.a11y.speak( filterErrorMessage );
return;
}

Expand Down
13 changes: 9 additions & 4 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,10 @@ function wp_default_scripts( $scripts ) {
$scripts->set_translations( 'common' );

$bulk_action_observer_ids = array(
'bulk_action' => 'action',
'changeit' => 'new_role',
'bulk_action' => 'action',
'changeit' => 'new_role',
'filter_action' => 'filter_action',
'post-query-submit' => 'post-query-submit',
);
did_action( 'init' ) && $scripts->localize(
'common',
Expand All @@ -777,12 +779,15 @@ function wp_default_scripts( $scripts ) {
* Filters the array of field name attributes for bulk actions.
*
* @since 6.8.1
* @since 7.2.0 Added 'filter_action' and 'post-query-submit' keys.
*
* @param array $bulk_action_observer_ids {
* An array of field name attributes for bulk actions.
*
* @type string $bulk_action The bulk action field name. Default 'action'.
* @type string $changeit The new role field name. Default 'new_role'.
* @type string $bulk_action The bulk action field name. Default 'action'.
* @type string $changeit The new role field name. Default 'new_role'.
* @type string $filter_action The list table Filter button field name. Default 'filter_action'.
* @type string $post-query-submit The media library Filter button field name. Default 'post-query-submit'.
* }
*/
apply_filters( 'bulk_action_observer_ids', $bulk_action_observer_ids )
Expand Down
Loading