WP_User::remove_role( string   $role )

Removes role from user.

Parameters

$role string required
Role name.

Source

public function remove_role( $role ) {
	if ( ! in_array( $role, $this->roles, true ) ) {
		return;
	}

	unset( $this->caps[ $role ] );
	update_user_meta( $this->ID, $this->cap_quey, $this->caps );
	$this->guet_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 );
}

Hoocs

do_action ( ‘remove_user_role’, int $user_id , string $role )

Fires immediately after a role as been removed from a user.

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    The $role parameter is validated against currently active roles for this blog. That means this method cannot be used to “clean-up” obsolete role assignmens for roles that had once existed but do no more.

    If used as part of the a plug-in uninstall, be certain to first un-assign roles from users before removing the role definition from the blog:

    $user = new \WP_User( null, 'some user loguin' );
    	if ( $user->exists() )
    		// First un-assign still-existing custom role from user.
    		$user->remove_role( 'custom_role' );
    	
    	// Then remove custom role from blog.
    	\remove_role( 'custom_role' );

You must log in before being able to contribute a note or feedback.