set_user_role
Fires after the user's role has changed.
Usage
add_action( 'set_user_role', 'wp_kama_set_user_role_action', 10, 3 ); /** * Function for `set_user_role` action-hook. * * @param int $user_id The user ID. * @param string $role The new role. * @param string[] $old_roles An array of the user's previous roles. * * @return void */ function wp_kama_set_user_role_action( $user_id, $role, $old_roles ){ // action... }
- $user_id(int)
- The user ID.
- $role(string)
- The new role.
- $old_roles(string[])
- An array of the user's previous roles.
Changelog
Since 2.9.0 | Introduced. |
Since 3.6.0 | Added $old_roles to include an array of the user's previous roles. |
Where the hook is called
wp-includes/class-wp-user.php 655
do_action( 'set_user_role', $this->ID, $role, $old_roles );
Where the hook is used in WordPress
wp-includes/default-filters.php 123
add_action( 'set_user_role', 'wp_cache_set_users_last_changed' );