WordPress at Your Fingertips
function is not described

WP_User::remove_role() public WP 2.0.0

Remove role from user.

{} It's a method of the class: WP_User{}

Hooks from the method

Return

null. Nothing.

Usage

$WP_User = new WP_User();
$WP_User->remove_role( $role );
$role(string) (required)
Role name.

Changelog

Since 2.0.0 Introduced.

Code of WP_User::remove_role() WP 5.8.1

public function remove_role( $role ) {
	if ( ! in_array( $role, $this->roles, true ) ) {
		return;
	}
	unset( $this->caps[ $role ] );
	update_user_meta( $this->ID, $this->cap_key, $this->caps );
	$this->get_role_caps();
	$this->update_user_level_from_caps();

	/**
	 * Fires immediately after a role as been removed from a user.
	 *
	 * @since 4.3.0
	 *
	 * @param int    $user_id The user ID.
	 * @param string $role    The removed role.
	 */
	do_action( 'remove_user_role', $this->ID, $role );
}