Make WordPress Core

Changeset 38647


Ignore:
Timestamp:
09/23/2016 08:32:48 PM (10 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.

Location:
trunk/src/wp-admin
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-comments.php

    r37914 r38647  
    8181                                break;
    8282                }
     83        }
     84
     85        if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {
     86                /**
     87                 * Fires when a custom bulk action should be handled.
     88                 *
     89                 * The redirect link should be modified with success or failure feedback
     90                 * from the action to be used to display feedback to the user.
     91                 *
     92                 * @since 4.7.0
     93                 *
     94                 * @param string $redirect_to The redirect URL.
     95                 * @param string $doaction    The action being taken.
     96                 * @param array  $comment_ids The comments to take the action on.
     97                 */
     98                $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $comment_ids );
    8399        }
    84100
  • trunk/src/wp-admin/edit-tags.php

    r38629 r38647  
    196196                $location = add_query_arg( array( 'error' => true, 'message' => 5 ), $location );
    197197        break;
     198default:
     199        if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) {
     200                break;
     201        }
     202        check_admin_referer( 'bulk-tags' );
     203        $tags = (array) $_REQUEST['delete_tags'];
     204        /**
     205         * Fires when a custom bulk action should be handled.
     206         *
     207         * The sendback link should be modified with success or failure feedback
     208         * from the action to be used to display feedback to the user.
     209         *
     210         * @since 4.7.0
     211         *
     212         * @param string $location The redirect URL.
     213         * @param string $action   The action being taken.
     214         * @param array  $tags     The tag IDs to take the action on.
     215         */
     216        $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags );
     217        break;
    198218}
    199219
    … …  
    211231         *
    212232         * @since 4.6.0
    213          * 
     233         *
    214234         * @param string $location The destination URL.
    215235         * @param object $tax      The taxonomy object.
  • trunk/src/wp-admin/edit.php

    r38076 r38647  
    162162                                }
    163163                        }
     164                        break;
     165                default:
     166                        /**
     167                         * Fires when a custom bulk action should be handled.
     168                         *
     169                         * The sendback link should be modified with success or failure feedback
     170                         * from the action to be used to display feedback to the user.
     171                         *
     172                         * @since 4.7.0
     173                         *
     174                         * @param string $sendback The redirect URL.
     175                         * @param string $doaction The action being taken.
     176                         * @param array  $post_ids The post IDs to take the action on.
     177                         */
     178                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $post_ids );
    164179                        break;
    165180        }
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r38334 r38647  
    437437        protected function bulk_actions( $which = '' ) {
    438438                if ( is_null( $this->_actions ) ) {
    439                         $no_new_actions = $this->_actions = $this->get_bulk_actions();
     439                        $this->_actions = $this->get_bulk_actions();
    440440                        /**
    441441                         * Filters the list table Bulk Actions drop-down.
    … …  
    451451                         */
    452452                        $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
    453                         $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
    454453                        $two = '';
    455454                } else {
  • 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'] ) ) );
  • trunk/src/wp-admin/network/site-themes.php

    r38320 r38647  
    123123                        }
    124124                        break;
     125                default:
     126                        if ( isset( $_POST['checked'] ) ) {
     127                                check_admin_referer( 'bulk-themes' );
     128                                $themes = (array) $_POST['checked'];
     129                                $n = count( $themes );
     130                                /**
     131                                 * Fires when a custom bulk action should be handled.
     132                                 *
     133                                 * The redirect link should be modified with success or failure feedback
     134                                 * from the action to be used to display feedback to the user.
     135                                 *
     136                                 * @since 4.7.0
     137                                 *
     138                                 * @param string $referer The redirect URL.
     139                                 * @param string $action  The action being taken.
     140                                 * @param array  $themes  The themes to take the action on.
     141                                 * @param int    $site_id The current site id
     142                                 */
     143                                $referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes, $id );
     144                        } else {
     145                                $action = 'error';
     146                                $n = 'none';
     147                        }
    125148        }
    126149
  • trunk/src/wp-admin/network/site-users.php

    r38320 r38647  
    165165                        }
    166166                        break;
     167                default:
     168                        if ( ! isset( $_REQUEST['users'] ) ) {
     169                                break;
     170                        }
     171                        check_admin_referer( 'bulk-users' );
     172                        $userids = $_REQUEST['users'];
     173                        /**
     174                         * Fires when a custom bulk action should be handled.
     175                         *
     176                         * The redirect link should be modified with success or failure feedback
     177                         * from the action to be used to display feedback to the user.
     178                         *
     179                         * @since 4.7.0
     180                         *
     181                         * @param string $referer The redirect URL.
     182                         * @param string $action  The action being taken.
     183                         * @param array  $userids The users to take the action on.
     184                         * @param int    $id      The id of the current site
     185                         */
     186                        $referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $userids, $id );
     187                        $update = $action;
     188                        break;
    167189        }
    168190
  • trunk/src/wp-admin/network/sites.php

    r38305 r38647  
    161161                                        }
    162162                                }
     163                                if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
     164                                        $redirect_to = wp_get_referer();
     165                                        $blogs = (array) $_POST['allblogs'];
     166                                        /**
     167                                         * Fires when a custom bulk action should be handled.
     168                                         *
     169                                         * The redirect link should be modified with success or failure feedback
     170                                         * from the action to be used to display feedback to the user.
     171                                         *
     172                                         * @since 4.7.0
     173                                         *
     174                                         * @param string $redirect_to The redirect URL.
     175                                         * @param string $doaction      The action being taken.
     176                                         * @param array  $blogs       The blogs to take the action on.
     177                                         * @param int    $site_id     The current site id.
     178                                         */
     179                                        $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id );
     180                                        wp_safe_redirect( $redirect_to );
     181                                        exit();
     182                                }
    163183                        } else {
    164184                                $location = network_admin_url( 'sites.php' );
  • trunk/src/wp-admin/network/themes.php

    r37914 r38647  
    196196                        ), network_admin_url( 'themes.php' ) ) );
    197197                        exit;
     198                default:
     199                        $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     200                        if ( empty( $themes ) ) {
     201                                wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
     202                                exit;
     203                        }
     204                        check_admin_referer( 'bulk-themes' );
     205
     206                        /**
     207                         * Fires when a custom bulk action should be handled.
     208                         *
     209                         * The redirect link should be modified with success or failure feedback
     210                         * from the action to be used to display feedback to the user.
     211                         *
     212                         * @since 4.7.0
     213                         *
     214                         * @param string $referer   The redirect URL.
     215                         * @param string $action    The action being taken.
     216                         * @param array  $themes    The themes to take the action on.
     217                         */
     218                        $referer = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes );
     219
     220                        wp_safe_redirect( $referer );
     221                        exit;
    198222        }
     223
    199224}
    200225
  • trunk/src/wp-admin/network/users.php

    r37914 r38647  
    9494                                }
    9595
     96                                if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
     97                                        $sendback = wp_get_referer();
     98
     99                                        $user_ids = (array) $_POST['allusers'];
     100                                        /**
     101                                         * Fires when a custom bulk action should be handled.
     102                                         *
     103                                         * The sendback link should be modified with success or failure feedback
     104                                         * from the action to be used to display feedback to the user.
     105                                         *
     106                                         * @since 4.7.0
     107                                         *
     108                                         * @param string $sendback The redirect URL.
     109                                         * @param string $doaction The action being taken.
     110                                         * @param array  $user_ids The users to take the action on.
     111                                         */
     112                                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids );
     113
     114                                        wp_safe_redirect( $sendback );
     115                                        exit();
     116                                }
     117
    96118                                wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
    97119                        } else {
  • trunk/src/wp-admin/plugins.php

    r38325 r38647  
    357357                        }
    358358                        break;
     359
     360                default:
     361                        if ( isset( $_POST['checked'] ) ) {
     362                                check_admin_referer('bulk-plugins');
     363                                $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
     364                                $sendback = wp_get_referer();
     365
     366                                /**
     367                                 * Fires when a custom bulk action should be handled.
     368                                 *
     369                                 * The sendback link should be modified with success or failure feedback
     370                                 * from the action to be used to display feedback to the user.
     371                                 *
     372                                 * @since 4.7.0
     373                                 *
     374                                 * @param string $sendback The redirect URL.
     375                                 * @param string $action   The action being taken.
     376                                 * @param array  $plugins  The plugins to take the action on.
     377                                 */
     378                                $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $action, $plugins );
     379
     380                                wp_safe_redirect( $sendback );
     381                                exit;
     382                        }
     383                        break;
    359384        }
     385
    360386}
    361387
  • trunk/src/wp-admin/upload.php

    r37958 r38647  
    164164                        $location = add_query_arg( 'deleted', count( $post_ids ), $location );
    165165                        break;
     166                default:
     167                        /**
     168                         * Fires when a custom bulk action should be handled.
     169                         *
     170                         * The redirect link should be modified with success or failure feedback
     171                         * from the action to be used to display feedback to the user.
     172                         *
     173                         * @since 4.7.0
     174                         *
     175                         * @param string $location The redirect URL.
     176                         * @param string $doaction The action being taken.
     177                         * @param array  $post_ids The posts to take the action on.
     178                         */
     179                        $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $doaction, $post_ids );
    166180        }
    167181
  • trunk/src/wp-admin/users.php

    r37914 r38647  
    411411        }
    412412
     413        if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
     414                $userids = $_REQUEST['users'];
     415                $sendback = wp_get_referer();
     416
     417                /**
     418                 * Fires when a custom bulk action should be handled.
     419                 *
     420                 * The sendback link should be modified with success or failure feedback
     421                 * from the action to be used to display feedback to the user.
     422                 *
     423                 * @since 4.7.0
     424                 *
     425                 * @param string $sendback The redirect URL.
     426                 * @param string $action   The action being taken.
     427                 * @param array  $userids  The users to take the action on.
     428                 */
     429                $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $wp_list_table->current_action(), $userids );
     430
     431                wp_safe_redirect( $sendback );
     432                exit;
     433        }
     434
    413435        $wp_list_table->prepare_items();
    414436        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
Note: See TracChangeset for help on using the changeset viewer.