Quick/Bulk Edit: By the power vested in me, I hereby declare the top bulk actions and the bottom bulk actions joined forever in MatrimonyScript.

This joyous marriage means that users will no longer find a selected top bulk action on a list table unexpectedly being applied instead of their selected bottom bulk action. The top and bottom controls for changing user roles are equally wedded forever too.

Props clayray, subrataemfluence, garrett-eclipse, pbiron, hareesh-pillai

Fixes #46872


git-svn-id: https://develop.svn.wordpress.org/trunk@49944 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2021-01-07 16:21:09 +00:00
parent 6409904a19
commit 9010454dfe
13 changed files with 81 additions and 32 deletions
+57 -2
View File
@@ -1219,6 +1219,62 @@ $document.ready( function() {
});
});
/**
* Marries a secondary control to its primary control.
*
* @param {jQuery} topSelector The top selector element.
* @param {jQuery} topSubmit The top submit element.
* @param {jQuery} bottomSelector The bottom selector element.
* @param {jQuery} bottomSubmit The bottom submit element.
* @return {void}
*/
function marryControls( topSelector, topSubmit, bottomSelector, bottomSubmit ) {
/**
* Updates the primary selector when the secondary selector is changed.
*
* @since 5.7.0
*
* @return {void}
*/
function updateTopSelector() {
topSelector.val($(this).val());
}
bottomSelector.on('change', updateTopSelector);
/**
* Updates the secondary selector when the primary selector is changed.
*
* @since 5.7.0
*
* @return {void}
*/
function updateBottomSelector() {
bottomSelector.val($(this).val());
}
topSelector.on('change', updateBottomSelector);
/**
* Triggers the primary submit when then secondary submit is clicked.
*
* @since 5.7.0
*
* @return {void}
*/
function triggerSubmitClick(e) {
e.preventDefault();
e.stopPropagation();
topSubmit.trigger('click');
}
bottomSubmit.on('click', triggerSubmitClick);
}
// Marry the secondary "Bulk actions" controls to the primary controls:
marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') );
// Marry the secondary "Change role to" controls to the primary controls:
marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
/**
* Shows row actions on focus of its parent container element or any other elements contained within.
*
@@ -1321,9 +1377,8 @@ $document.ready( function() {
pageInput.closest('form').submit( function() {
/*
* action = bulk action dropdown at the top of the table
* action2 = bulk action dropdow at the bottom of the table
*/
if ( $('select[name="action"]').val() == -1 && $('select[name="action2"]').val() == -1 && pageInput.val() == currentPage )
if ( $('select[name="action"]').val() == -1 && pageInput.val() == currentPage )
pageInput.val('1');
});
}
+1 -1
View File
@@ -808,7 +808,7 @@ window.commentReply = {
commentReply.toggle($(this).parent());
});
$('#doaction, #doaction2, #post-query-submit').click(function(){
$('#doaction, #post-query-submit').click(function(){
if ( $('#the-comment-list #replyrow').length > 0 )
commentReply.close();
});
+1 -1
View File
@@ -139,7 +139,7 @@ window.wp = window.wp || {};
/**
* Adds onclick events to the apply buttons.
*/
$('#doaction, #doaction2').click(function(e){
$('#doaction').click(function(e){
var n;
t.whichBulkButtonId = $( this ).attr( 'id' );
+3 -4
View File
@@ -178,13 +178,12 @@
$( '#find-posts-close' ).click( findPosts.close );
// Binds the bulk action events to the submit buttons.
$( '#doaction, #doaction2' ).click( function( event ) {
$( '#doaction' ).click( function( event ) {
/*
* Retrieves all select elements for bulk actions that have a name starting with `action`
* and handle its action based on its value.
* Handle the bulk action based on its value.
*/
$( 'select[name^="action"]' ).each( function() {
$( 'select[name="action"]' ).each( function() {
var optionValue = $( this ).val();
if ( 'attach' === optionValue ) {
+10
View File
@@ -492,6 +492,16 @@ input[type="number"].tiny-text {
margin: 0 8px 0 0;
}
/* @since 5.7.0 secondary bulk action controls require JS. */
.no-js label[for="bulk-action-selector-bottom"],
.no-js select#bulk-action-selector-bottom,
.no-js input#doaction2,
.no-js label[for="new_role2"],
.no-js select#new_role2,
.no-js input#changeit2 {
display: none;
}
.tablenav .actions select {
float: left;
margin-right: 6px;
+1 -1
View File
@@ -31,7 +31,7 @@ if ( $doaction ) {
$doaction = 'delete';
} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
$comment_ids = $_REQUEST['delete_comments'];
$doaction = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2'];
$doaction = $_REQUEST['action'];
} elseif ( isset( $_REQUEST['ids'] ) ) {
$comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
} elseif ( wp_get_referer() ) {
@@ -526,10 +526,6 @@ class WP_List_Table {
return $_REQUEST['action'];
}
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) {
return $_REQUEST['action2'];
}
return false;
}
@@ -171,7 +171,7 @@ class WP_Terms_List_Table extends WP_List_Table {
* @return string
*/
public function current_action() {
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) {
if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && 'delete' === $_REQUEST['action'] ) {
return 'bulk-delete';
}
@@ -335,8 +335,7 @@ class WP_Users_List_Table extends WP_List_Table {
* @return string The bulk action required.
*/
public function current_action() {
if ( ( isset( $_REQUEST['changeit'] ) || isset( $_REQUEST['changeit2'] ) ) &&
( ! empty( $_REQUEST['new_role'] ) || ! empty( $_REQUEST['new_role2'] ) ) ) {
if ( isset( $_REQUEST['changeit'] ) && ! empty( $_REQUEST['new_role'] ) ) {
return 'promote';
}
+1 -6
View File
@@ -140,12 +140,7 @@ if ( $action ) {
case 'promote':
check_admin_referer( 'bulk-users' );
$editable_roles = get_editable_roles();
$role = false;
if ( ! empty( $_REQUEST['new_role2'] ) ) {
$role = $_REQUEST['new_role2'];
} elseif ( ! empty( $_REQUEST['new_role'] ) ) {
$role = $_REQUEST['new_role'];
}
$role = $_REQUEST['new_role'];
if ( empty( $editable_roles[ $role ] ) ) {
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
+2 -2
View File
@@ -177,8 +177,8 @@ if ( isset( $_GET['action'] ) ) {
break;
case 'allblogs':
if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
$doaction = -1 != $_POST['action'] ? $_POST['action'] : $_POST['action2'];
if ( isset( $_POST['action'] ) && isset( $_POST['allblogs'] ) ) {
$doaction = $_POST['action'];
foreach ( (array) $_POST['allblogs'] as $key => $val ) {
if ( '0' != $val && get_network()->site_id != $val ) {
+2 -2
View File
@@ -46,10 +46,10 @@ if ( isset( $_GET['action'] ) ) {
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
}
if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
if ( isset( $_POST['action'] ) && isset( $_POST['allusers'] ) ) {
check_admin_referer( 'bulk-users-network' );
$doaction = -1 != $_POST['action'] ? $_POST['action'] : $_POST['action2'];
$doaction = $_POST['action'];
$userfunction = '';
foreach ( (array) $_POST['allusers'] as $user_id ) {
+1 -6
View File
@@ -112,12 +112,7 @@ switch ( $wp_list_table->current_action() ) {
}
$editable_roles = get_editable_roles();
$role = false;
if ( ! empty( $_REQUEST['new_role2'] ) ) {
$role = $_REQUEST['new_role2'];
} elseif ( ! empty( $_REQUEST['new_role'] ) ) {
$role = $_REQUEST['new_role'];
}
$role = $_REQUEST['new_role'];
if ( ! $role || empty( $editable_roles[ $role ] ) ) {
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );