[wp-trac] [WordPress Trac] #16031: New bulk actions hook missing catcher behavior

WordPress Trac noreply at wordpress.org
Sun Aug 30 01:58:54 UTC 2015


#16031: New bulk actions hook missing catcher behavior
----------------------------+-----------------------------
 Reporter:  Veraxus         |       Owner:
     Type:  enhancement     |      Status:  assigned
 Priority:  normal          |   Milestone:  Future Release
Component:  Administration  |     Version:  3.1
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+-----------------------------
Changes (by Veraxus):

 * keywords:  needs-patch => has-patch


Comment:

 Comprehensive patch has been uploaded.

 * Reverts changeset 17297
 * Adds filter `"handle_other_bulk_action-{$screen_id}"` to all appropriate
 admin screens that use list tables.

 Filter takes the following arguments:

 * `$redirect_url` - '''String.''' A redirect URL to return once handling
 is finished.
 * `$object_ids` - '''Array.''' Contains the ids of the checked items.
 * `$current_action` - '''String.''' The current action.
 * `$site_id` - '''Int.''' MS only. The id of the current site.

 See previous comment for example usage. To test drive the hook, use the
 following plugin…

 {{{
 <?php
 /*
 Plugin Name: WP List Table Filter Tests
 Plugin URI:
 Description: Tests the new list table filter.
 Author: Matt van Andel
 Version: 1.0
 Author URI:
 */

 // Enable links for testing
 add_filter( 'pre_option_link_manager_enabled', '__return_true' );

 // Screens to test
 $lt_screens = array(
         'edit-comments',
         'edit-post_tag',
         'edit-category',
         'edit-post',
         'edit-page',
         'link-manager',
         'edit-link_category',
         //'plugin-install', // ⇐ not applicable to this screen
         'plugins',
         'upload',
         'users',
         //'themes', // ⇐ not applicable to this screen
         'themes-network',
         'sites-network',
         'site-users-network',
         'users-network',
         'site-themes-network',
         'plugins-network',
 );

 // Apply to all specified screens
 foreach ( $lt_screens as $screen ) {

         add_filter( 'bulk_actions-'.$screen, function ( $actions ) {
                 //unset( $actions['trash'] );
                 $actions['custom'] = __( 'Custom' );
                 return $actions;
         } );

         add_action( 'handle_other_bulk_action-'.$screen, function (
 $redirect_to, $items, $current_action, $site_id = null ) {
                 $redirect_to = remove_query_arg( 'custom_completed',
 $redirect_to );
                 if ( 'custom' === $current_action ) {
                         $redirect_to = add_query_arg( 'custom_completed',
 count( $items ), $redirect_to );
                 }
                 return $redirect_to;
         }, 10, 4 );

 }

 // Admin notice handlers
 add_action( 'admin_notices', 'lt_filter_tests_admin_notice' );
 add_action( 'network_admin_notices', 'lt_filter_tests_admin_notice' );

 function lt_filter_tests_admin_notice () {
         global $current_screen;

         if ( !empty($_REQUEST['custom_completed']) )
                 echo "<div id=\"message\" class=\"updated fade\"><p>Custom
 bulk action caught for {$_REQUEST['custom_completed']} items on
 {$current_screen->id}!</p></div>";
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/16031#comment:60>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list