Allow custom bulk actions in admin list tables.
Bulk action filtering was introduced in 3.1, but only to remove default bulk actions, not add new ones. Bulk actions can now be registered for all admin list table dropdowns via the `bulk_actions-{get_current_screen()->id}` filter. Handling custom bulk actions can be performed in the corresponding and newly introduced `handle_bulk_actions-${get_current_screen()->id}` filter. Props scribu, flixos90, Veraxus. See #16031. git-svn-id: https://develop.svn.wordpress.org/trunk@38647 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8bc6917cc3
commit
c75fb5e9ca
@ -82,6 +82,22 @@ if ( $doaction ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $redirect_to The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $comment_ids The comments to take the action on.
|
||||
*/
|
||||
$redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $comment_ids );
|
||||
}
|
||||
|
||||
wp_defer_comment_counting( false );
|
||||
|
||||
if ( $approved )
|
||||
|
@ -195,6 +195,26 @@ case 'editedtag':
|
||||
else
|
||||
$location = add_query_arg( array( 'error' => true, 'message' => 5 ), $location );
|
||||
break;
|
||||
default:
|
||||
if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) {
|
||||
break;
|
||||
}
|
||||
check_admin_referer( 'bulk-tags' );
|
||||
$tags = (array) $_REQUEST['delete_tags'];
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The sendback link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $location The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $tags The tag IDs to take the action on.
|
||||
*/
|
||||
$location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! $location && ! empty( $_REQUEST['_wp_http_referer'] ) ) {
|
||||
@ -210,7 +230,7 @@ if ( $location ) {
|
||||
* Filters the taxonomy redirect destination URL.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
*
|
||||
* @param string $location The destination URL.
|
||||
* @param object $tax The taxonomy object.
|
||||
*/
|
||||
|
@ -162,6 +162,21 @@ if ( $doaction ) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The sendback link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $sendback The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $post_ids The post IDs to take the action on.
|
||||
*/
|
||||
$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $post_ids );
|
||||
break;
|
||||
}
|
||||
|
||||
$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
|
||||
|
@ -436,7 +436,7 @@ class WP_List_Table {
|
||||
*/
|
||||
protected function bulk_actions( $which = '' ) {
|
||||
if ( is_null( $this->_actions ) ) {
|
||||
$no_new_actions = $this->_actions = $this->get_bulk_actions();
|
||||
$this->_actions = $this->get_bulk_actions();
|
||||
/**
|
||||
* Filters the list table Bulk Actions drop-down.
|
||||
*
|
||||
@ -450,7 +450,6 @@ class WP_List_Table {
|
||||
* @param array $actions An array of the available bulk actions.
|
||||
*/
|
||||
$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
|
||||
$this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
|
||||
$two = '';
|
||||
} else {
|
||||
$two = '2';
|
||||
|
@ -19,17 +19,34 @@ $doaction = $wp_list_table->current_action();
|
||||
if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
|
||||
check_admin_referer( 'bulk-bookmarks' );
|
||||
|
||||
$redirect_to = admin_url( 'link-manager.php' );
|
||||
$bulklinks = (array) $_REQUEST['linkcheck'];
|
||||
|
||||
if ( 'delete' == $doaction ) {
|
||||
$bulklinks = (array) $_REQUEST['linkcheck'];
|
||||
foreach ( $bulklinks as $link_id ) {
|
||||
$link_id = (int) $link_id;
|
||||
|
||||
wp_delete_link( $link_id );
|
||||
}
|
||||
|
||||
wp_redirect( add_query_arg('deleted', count( $bulklinks ), admin_url( 'link-manager.php' ) ) );
|
||||
exit;
|
||||
$redirect_to = add_query_arg( 'deleted', count( $bulklinks ), $redirect_to );
|
||||
} else {
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $redirect_to The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $bulklinks The links to take the action on.
|
||||
*/
|
||||
$redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $bulklinks );
|
||||
}
|
||||
wp_redirect( $redirect_to );
|
||||
exit;
|
||||
} elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
|
||||
wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
||||
exit;
|
||||
|
@ -122,6 +122,29 @@ if ( $action ) {
|
||||
$n = 'none';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ( isset( $_POST['checked'] ) ) {
|
||||
check_admin_referer( 'bulk-themes' );
|
||||
$themes = (array) $_POST['checked'];
|
||||
$n = count( $themes );
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $referer The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $themes The themes to take the action on.
|
||||
* @param int $site_id The current site id
|
||||
*/
|
||||
$referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes, $id );
|
||||
} else {
|
||||
$action = 'error';
|
||||
$n = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'allowedthemes', $allowed_themes );
|
||||
|
@ -164,6 +164,28 @@ if ( $action ) {
|
||||
$update = 'err_promote';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ( ! isset( $_REQUEST['users'] ) ) {
|
||||
break;
|
||||
}
|
||||
check_admin_referer( 'bulk-users' );
|
||||
$userids = $_REQUEST['users'];
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $referer The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $userids The users to take the action on.
|
||||
* @param int $id The id of the current site
|
||||
*/
|
||||
$referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $userids, $id );
|
||||
$update = $action;
|
||||
break;
|
||||
}
|
||||
|
||||
wp_safe_redirect( add_query_arg( 'update', $update, $referer ) );
|
||||
|
@ -160,6 +160,26 @@ if ( isset( $_GET['action'] ) ) {
|
||||
wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
|
||||
}
|
||||
}
|
||||
if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
|
||||
$redirect_to = wp_get_referer();
|
||||
$blogs = (array) $_POST['allblogs'];
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $redirect_to The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $blogs The blogs to take the action on.
|
||||
* @param int $site_id The current site id.
|
||||
*/
|
||||
$redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id );
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
$location = network_admin_url( 'sites.php' );
|
||||
if ( ! empty( $_REQUEST['paged'] ) ) {
|
||||
|
@ -195,7 +195,32 @@ if ( $action ) {
|
||||
's' => $s
|
||||
), network_admin_url( 'themes.php' ) ) );
|
||||
exit;
|
||||
default:
|
||||
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
if ( empty( $themes ) ) {
|
||||
wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
|
||||
exit;
|
||||
}
|
||||
check_admin_referer( 'bulk-themes' );
|
||||
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $referer The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $themes The themes to take the action on.
|
||||
*/
|
||||
$referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes );
|
||||
|
||||
wp_safe_redirect( $referer );
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$wp_list_table->prepare_items();
|
||||
|
@ -93,6 +93,28 @@ if ( isset( $_GET['action'] ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
|
||||
$sendback = wp_get_referer();
|
||||
|
||||
$user_ids = (array) $_POST['allusers'];
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The sendback link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $sendback The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $user_ids The users to take the action on.
|
||||
*/
|
||||
$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids );
|
||||
|
||||
wp_safe_redirect( $sendback );
|
||||
exit();
|
||||
}
|
||||
|
||||
wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
|
||||
} else {
|
||||
$location = network_admin_url( 'users.php' );
|
||||
|
@ -356,7 +356,33 @@ if ( $action ) {
|
||||
update_site_option( 'recently_activated', array() );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( isset( $_POST['checked'] ) ) {
|
||||
check_admin_referer('bulk-plugins');
|
||||
$plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
$sendback = wp_get_referer();
|
||||
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The sendback link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $sendback The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $plugins The plugins to take the action on.
|
||||
*/
|
||||
$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $action, $plugins );
|
||||
|
||||
wp_safe_redirect( $sendback );
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$wp_list_table->prepare_items();
|
||||
|
@ -163,6 +163,20 @@ if ( $doaction ) {
|
||||
}
|
||||
$location = add_query_arg( 'deleted', count( $post_ids ), $location );
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The redirect link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $location The redirect URL.
|
||||
* @param string $doaction The action being taken.
|
||||
* @param array $post_ids The posts to take the action on.
|
||||
*/
|
||||
$location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $doaction, $post_ids );
|
||||
}
|
||||
|
||||
wp_redirect( $location );
|
||||
|
@ -410,6 +410,28 @@ default:
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
|
||||
$userids = $_REQUEST['users'];
|
||||
$sendback = wp_get_referer();
|
||||
|
||||
/**
|
||||
* Fires when a custom bulk action should be handled.
|
||||
*
|
||||
* The sendback link should be modified with success or failure feedback
|
||||
* from the action to be used to display feedback to the user.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param string $sendback The redirect URL.
|
||||
* @param string $action The action being taken.
|
||||
* @param array $userids The users to take the action on.
|
||||
*/
|
||||
$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $wp_list_table->current_action(), $userids );
|
||||
|
||||
wp_safe_redirect( $sendback );
|
||||
exit;
|
||||
}
|
||||
|
||||
$wp_list_table->prepare_items();
|
||||
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
|
||||
if ( $pagenum > $total_pages && $total_pages > 0 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user