[wp-trac] [WordPress Trac] #16031: Bulk actions: Reactivate bulk actions hook + add hander hook for all admin screens
WordPress Trac
noreply at wordpress.org
Thu Oct 13 17:06:24 UTC 2016
#16031: Bulk actions: Reactivate bulk actions hook + add hander hook for all admin
screens
----------------------------+------------------------
Reporter: Veraxus | Owner: ericlewis
Type: enhancement | Status: assigned
Priority: normal | Milestone: 4.7
Component: Administration | Version: 3.1
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
----------------------------+------------------------
Comment (by ericlewis):
Replying to [comment:94 johnbillion]:
> These should either be statically named hooks, or a better way of
clearly passing different formats and number of data to the hooks is
needed.
We can't statically name the hooks across the board, as some of the hooks
are covering multiple screens. eg. the
[https://github.com/WordPress/WordPress/blob/acd764a1d3e599797a5d875f5721f76f81638cf9
/wp-admin/edit.php#L178 edit.php handle_bulk_actions-* hook] invokes
`handle_bulk_actions-edit-post`, `handle_bulk_actions-edit-page` and
``handle_bulk_actions-my-custom-post-type`.
If we want statically named hooks here, perhaps we could change all hooks
to use a single hook, `handle_bulk_actions`, and expect developers to
perform the screen check in their callback. Since different screens will
include different contextual data, perhaps we consolidate it in an array
in a `$context` argument. eg.
{{{
#!php
// For users.php
$context = array(
'user_ids' => $userids
);
// For network/site-themes.php
$context = array(
'themes' => $themes,
'site_id' => $site_id
);
// The hook invocation might look like this
$redirect_to = apply_filters( 'handle_bulk_actions', $redirect_to,
$do_action, $context );
// A bound callback might look like this
add_action( 'handle_bulk_actions', function($redirect_to, $do_action,
$context) {
if ( get_current_screen()->id !== 'users' ) {
return $redirect_to;
}
// Do something with $context['user_ids'], modify redirect link
return $redirect_to;
}, 10, 3 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/16031#comment:97>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list