[wp-trac] [WordPress Trac] #16031: New bulk actions hook missing catcher behavior
WordPress Trac
noreply at wordpress.org
Sun Aug 30 18:26:20 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:
----------------------------+-----------------------------
Comment (by Veraxus):
Replying to [comment:61 flixos90]:
> One thing we need to consider is whether the hook name should be tied to
the screen ID vs the action name. Sure, the action name is sent as
parameter, but still... For example, if you wanted to allow the same bulk
action for all post type tables, you would need to use multiple hooks.
Might be an edge-case, but I would assume that a bulk action hook would
contain the name of the bulk action.
Screens are really the only reliable way to target this. The issue is that
different screens can handle data very differently. You have screens that
deal with post types, screens that deal with users, and others that handle
taxonomies - for instance. If your hook target was the action, as opposed
to the screen, there's a higher likelihood of accidentally including code
that has unintended consequences. Targeting a specific screen is
definitely the best way to approach that.
And if, for instance, you wanted to easily filter ''all'' post types, it's
as easy as using `get_post_types()` and looping through your hook with the
`edit-` prefix.
{{{
add_action( 'init', function (){
$post_types = get_post_types();
// Apply to all registered post types
foreach ( $post_types as $screen ) {
add_filter( 'bulk_actions-edit-'.$screen, function (
$actions ) {
//unset( $actions['trash'] );
$actions['custom'] = __( 'Custom' );
return $actions;
} );
add_action( 'handle_other_bulk_action-edit-'.$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 );
}
});
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/16031#comment:62>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list