Action hook 'set_user_role'

in WP Core File wp-includes/class-wp-user.php at line 657

View Source

set_user_role

Action Hook
Description
Fires after the user's role has changed.

Hook Information

File Location wp-includes/class-wp-user.php View on GitHub
Hook Type Action
Line Number 657

Hook Parameters

Type Name Description
int $user_id The user ID.
string $role The new role.
string[] $old_roles An array of the user's previous roles.

Usage Examples

Basic Usage
<?php
// Hook into set_user_role
add_action('set_user_role', 'my_custom_function', 10, 3);

function my_custom_function($user_id, $role, $old_roles) {
    // Your custom code here
}

Source Code Context

wp-includes/class-wp-user.php:657 - How this hook is used in WordPress core
<?php
 652  		 *
 653  		 * @param int      $user_id   The user ID.
 654  		 * @param string   $role      The new role.
 655  		 * @param string[] $old_roles An array of the user's previous roles.
 656  		 */
 657  		do_action( 'set_user_role', $this->ID, $role, $old_roles );
 658  	}
 659  
 660  	/**
 661  	 * Chooses the maximum level the user has.
 662  	 *

PHP Documentation

<?php
/**
		 * Fires after the user's role has changed.
		 *
		 * @since 2.9.0
		 * @since 3.6.0 Added $old_roles to include an array of the user's previous roles.
		 *
		 * @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.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 3
  • File: wp-includes/class-wp-user.php
Related Hooks

Related hooks will be displayed here in future updates.