Quick/Bulk Edit: Add notice if no items selected.

Add an error notice if a user attempts to apply bulk edits with no items selected. Applies to post lists, comments, taxonomies, and plugins screens.

Props garrett-eclipse, nrqsnchz, sumitsingh, nihar007, royho, sabernhardt, oglekler, quadthemes, ankit-k-gupta, fnpen, ukdrahul, joedolson.
Fixes #45006, #58479.
Built from https://develop.svn.wordpress.org/trunk@59134


git-svn-id: http://core.svn.wordpress.org/trunk@58530 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-09-30 18:24:13 +00:00
parent 543ac83971
commit 0a4679908b
9 changed files with 88 additions and 16 deletions

View File

@ -625,7 +625,7 @@ class WP_List_Table {
echo "</select>\n";
submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
submit_button( __( 'Apply' ), 'action', 'bulk_action', false, array( 'id' => "doaction$two" ) );
echo "\n";
}

View File

@ -1114,7 +1114,7 @@ $( function() {
});
}
$document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error', makeNoticesDismissible );
$document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error wp-notice-added', makeNoticesDismissible );
// Init screen meta.
screenMeta.init();
@ -1276,6 +1276,80 @@ $( function() {
// Marry the secondary "Change role to" controls to the primary controls:
marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
var addAdminNotice = function( data ) {
var $notice = $( data.selector ),
$headerEnd = $( '.wp-header-end' ),
type,
dismissible,
$adminNotice;
delete data.selector;
dismissible = ( data.dismissible && data.dismissible === true ) ? ' is-dismissible' : '';
type = ( data.type ) ? data.type : 'info';
$adminNotice = '<div id="' + data.id + '" class="notice notice-' + data.type + dismissible + '"><p>' + data.message + '</p></div>';
// Check if this admin notice already exists.
if ( ! $notice.length ) {
$notice = $( '#' + data.id );
}
if ( $notice.length ) {
$notice.replaceWith( $adminNotice );
} else if ( $headerEnd.length ) {
$headerEnd.after( $adminNotice );
} else {
if ( 'customize' === pagenow ) {
$( '.customize-themes-notifications' ).append( $adminNotice );
} else {
$( '.wrap' ).find( '> h1' ).after( $adminNotice );
}
}
$document.trigger( 'wp-notice-added' );
};
$( '.bulkactions' ).parents( 'form' ).on( 'submit', function( event ) {
var form = this,
submitterName = event.originalEvent && event.originalEvent.submitter ? event.originalEvent.submitter.name : false;
// Observe submissions from posts lists for 'bulk_action' or users lists for 'new_role'.
var bulkFieldRelations = {
'bulk_action' : 'action',
'changeit' : 'new_role'
};
if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) {
return;
}
var values = new FormData(form);
var value = values.get( bulkFieldRelations[ submitterName ] ) || '-1';
// Check that the action is not the default one.
if ( value !== '-1' ) {
// Check that at least one item is selected.
var itemsSelected = form.querySelectorAll( '.wp-list-table tbody .check-column input[type="checkbox"]:checked' );
if ( itemsSelected.length > 0 ) {
return;
}
}
event.preventDefault();
event.stopPropagation();
$( 'html, body' ).animate( { scrollTop: 0 } );
var errorMessage = __( 'Please select at least one item to perform this action on.' );
addAdminNotice( {
id: 'no-items-selected',
type: 'error',
message: errorMessage,
dismissible: true,
} );
wp.a11y.speak( errorMessage );
});
/**
* Shows row actions on focus of its parent container element or any other elements contained within.
*

File diff suppressed because one or more lines are too long

View File

@ -148,7 +148,12 @@ window.wp = window.wp || {};
* Adds onclick events to the apply buttons.
*/
$('#doaction').on( 'click', function(e){
var n;
var n,
$itemsSelected = $( '#posts-filter .check-column input[type="checkbox"]:checked' );
if ( $itemsSelected.length < 1 ) {
return;
}
t.whichBulkButtonId = $( this ).attr( 'id' );
n = t.whichBulkButtonId.substr( 2 );

File diff suppressed because one or more lines are too long

View File

@ -2832,14 +2832,7 @@
// Bail if there were no items selected.
if ( ! itemsSelected.length ) {
event.preventDefault();
$( 'html, body' ).animate( { scrollTop: 0 } );
return wp.updates.addAdminNotice( {
id: 'no-items-selected',
className: 'notice-error is-dismissible',
message: __( 'Please select at least one item to perform this action on.' )
} );
bulkAction = false;
}
// Determine the type of request we're dealing with.

File diff suppressed because one or more lines are too long

View File

@ -754,7 +754,7 @@ function wp_default_scripts( $scripts ) {
)
);
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils', 'wp-a11y' ), false, 1 );
$scripts->set_translations( 'common' );
$scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-59133';
$wp_version = '6.7-alpha-59134';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.