Action hook 'remove_user_role'

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

View Source

remove_user_role

Action Hook
Description
Sets the role of the user. This will remove the previous roles of the user and assign the user the new one. You can set the role to an empty string and it will remove all of the roles from the user.

Hook Information

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

Hook Parameters

Type Name Description
string $role Role name.

Usage Examples

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

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

Source Code Context

wp-includes/class-wp-user.php:639 - How this hook is used in WordPress core
<?php
 634  			if ( ! $old_role || $old_role === $role ) {
 635  				continue;
 636  			}
 637  
 638  			/** This action is documented in wp-includes/class-wp-user.php */
 639  			do_action( 'remove_user_role', $this->ID, $old_role );
 640  		}
 641  
 642  		if ( $role && ! in_array( $role, $old_roles, true ) ) {
 643  			/** This action is documented in wp-includes/class-wp-user.php */
 644  			do_action( 'add_user_role', $this->ID, $role );

PHP Documentation

<?php
/**
	 * Sets the role of the user.
	 *
	 * This will remove the previous roles of the user and assign the user the
	 * new one. You can set the role to an empty string and it will remove all
	 * of the roles from the user.
	 *
	 * @since 2.0.0
	 *
	 * @param string $role Role name.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 1
  • File: wp-includes/class-wp-user.php
Related Hooks

Related hooks will be displayed here in future updates.