我正在添加批量操作assign
就像delete
.
add_filter( \'bulk_actions-users\', array( $this, \'add_bulk_action\' ) );
/**
* Add Bulk Assign Action.
* @param array $actions Current Actions.
* @return array All Actions along with assign action.
*/
public function add_bulk_action( $actions ) {
$actions[\'assign\'] = __( \'Assign\', \'wp-assign\' );
return $actions;
}
但是,在尝试触发分配操作时,我无法使用复选框选择用户。
add_action( \'load-users.php\', array( $this, \'trigger_bulk_actions\' ) );
public function trigger_query_actions() {
print_r( $_REQUEST );
}
触发删除操作时,我可以让用户进入
$_REQUEST
[12-Oct-2018 13:36:56 UTC] Array
(
[s] =>
[_wpnonce] => c48578ebab
[_wp_http_referer] => /professional/wp-admin/users.php?delete_count=18
[action] => delete
[new_role] =>
[paged] => 1
[users] => Array
(
[0] => 1
)
[action2] => -1
[new_role2] =>
)
为什么我的自定义中没有用户
assign
行动
谢谢
SO网友:Tom J Nowell
您处理请求不正确,load-users.php
不是正确的挂钩
相反,使用handle_bulk_actions-users
add_filter( \'handle_bulk_actions-users\', \'sanzeeb_bulk_action_handler_user\', 10, 3 );
function sanzeeb_bulk_action_handler_user( $redirect, $action, $object_ids ) {
// let\'s remove query args first
$redirect = remove_query_arg( array( \'assign\' ), $redirect );
// do something for "Assign" bulk action
if ( $doaction == \'assign\' ) {
// ...
其他注意事项:
这些都是非常通用的名称assign
trigger_query_actions
等prefix them e、 g。sanzeeb_assign
, 否则您将与其他插件发生冲突,请避免$_REQUEST
出于安全原因,这不仅仅是GET和POST,还包括COOKIE
SESSION
etc