WP_User remove_role is a function in WordPress that is used to remove a specific role or roles from a user. This function can be particularly useful when a user's access level needs to be changed, or if a user is no longer fulfilling a specific role.
Code example:
// Define the user ID $user_id = get_current_user_id();
// Get the current user $current_user = new WP_User( $user_id );
// Remove a specific role from the user $current_user->remove_role( 'subscriber' );
In this code example, we first define the user ID and then use that ID to retrieve the current user. We then use the remove_role function to remove the 'subscriber' role from the user.
Package/library:
This function is a part of the WordPress Core and is available in the WordPress wp-includes/user.php library.
PHP WP_User::remove_role - 30 examples found. These are the top rated real world PHP examples of WP_User::remove_role extracted from open source projects. You can rate examples to help us improve the quality of examples.