Change WordPress user roles and capabilities › Forums › New Feature Request › What action fires when users are added to a new role from the bulk edit users › Reply To: What action fires when users are added to a new role from the bulk edit users
16/03/2021 at 05:53
#7426
Vladimir
Keymaster
Hi,
URE uses WP_User::add_role() method (wp-includes/class-wp-user.php, #536 (WP v. 5.7) in this case, which fires this action
do_action( 'add_user_role', $this->ID, $role );
Check current page and additional parameters to execute your own hook only for the “Users” page and “Add Role” bulk action, not for other cases. For example, URE itself checks this:
if ( ( !empty( $_REQUEST['ure_add_role'] ) && !empty( $_REQUEST['ure_add_role_submit']) ) || ( !empty( $_REQUEST['ure_add_role_2'] ) && !empty( $_REQUEST['ure_add_role_submit_2'] ) ) ) {
// do something ...