WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2016 08:32:48 PM (3 years ago)
Author:
ericlewis
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/link-manager.php

    r37914 r38647  
    2020    check_admin_referer( 'bulk-bookmarks' );
    2121
     22    $redirect_to = admin_url( 'link-manager.php' );
     23    $bulklinks = (array) $_REQUEST['linkcheck'];
     24
    2225    if ( 'delete' == $doaction ) {
    23         $bulklinks = (array) $_REQUEST['linkcheck'];
    2426        foreach ( $bulklinks as $link_id ) {
    2527            $link_id = (int) $link_id;
     
    2830        }
    2931
    30         wp_redirect( add_query_arg('deleted', count( $bulklinks ), admin_url( 'link-manager.php' ) ) );
    31         exit;
     32        $redirect_to = add_query_arg( 'deleted', count( $bulklinks ), $redirect_to );
     33    } else {
     34        /**
     35         * Fires when a custom bulk action should be handled.
     36         *
     37         * The redirect link should be modified with success or failure feedback
     38         * from the action to be used to display feedback to the user.
     39         *
     40         * @since 4.7.0
     41         *
     42         * @param string $redirect_to The redirect URL.
     43         * @param string $doaction    The action being taken.
     44         * @param array  $bulklinks   The links to take the action on.
     45         */
     46        $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $bulklinks );
    3247    }
     48    wp_redirect( $redirect_to );
     49    exit;
    3350} elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
    3451     wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
Note: See TracChangeset for help on using the changeset viewer.