0

I am adding a bulk action assign just like 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;
}

However, while trying to trigger the assign action, I am not being able to get the users selected with checkbox.

add_action( 'load-users.php', array( $this, 'trigger_bulk_actions' ) );
public function trigger_query_actions() {
       print_r( $_REQUEST );
}

While triggering the delete action I can get users in $_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] => 
)

Why am I not getting users in my custom assign action?

Thanks!

0

You're handling the request incorrectly, load-users.php is not the correct hook

Instead, use 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' ) {
        // ...

Some other notes:

  • These are all very generic names assign trigger_query_actions etc, prefix them e.g. sanzeeb_assign, otherwise you'll clash with other plugins
  • Avoid $_REQUEST for security reasons, it's not just GET and POST, it's also COOKIE SESSION etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.