add_user_role action-hookWP 4.3.0

Fires immediately after the user has been given a new role.

Usage

add_action( 'add_user_role', 'wp_kama_add_user_role_action', 10, 2 );

/**
 * Function for `add_user_role` action-hook.
 * 
 * @param int    $user_id The user ID.
 * @param string $role    The new role.
 *
 * @return void
 */
function wp_kama_add_user_role_action( $user_id, $role ){

	// action...
}
$user_id(int)
The user ID.
$role(string)
The new role.

Changelog

Since 4.3.0 Introduced.

Where the hook is called

WP_User::add_role()
add_user_role
WP_User::set_role()
add_user_role
wp-includes/class-wp-user.php 562
do_action( 'add_user_role', $this->ID, $role );
wp-includes/class-wp-user.php 637
do_action( 'add_user_role', $this->ID, $role );

Where the hook is used in WordPress

wp-includes/default-filters.php 122
add_action( 'add_user_role', 'wp_cache_set_users_last_changed' );