How to Remove a User Role from WordPress (with example)

2.8461538461538 from 5
from 13 user
(Rate this post)
How to Remove a User Role from WordPress (with example)

remove_role function in WordPress has a simple syntax. remove_role only gets a role name and if it exists, this function will remove the role from WordPress. We're going to remove the "Contributor" role from our WordPress for an example.

What are user roles in WordPress?

As you must know, every user registers with a user role in WordPress.

WordPress has a few default user roles with different capabilities:

  • Super Admin
  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber

User roles are essential for developing a legitimate ACL (read more about ACL on Wikipedia).

Developers most of the time give access to a specific user role to modify data or run functionalities in the admin panel.

Not every user must have access to moderation functionalities, so WordPress introduced user roles to control user access.

If you are the first user of your WP, you are most likely a Super Admin.

You can create other users by using the admin panel or through public user registration.

Super Admin can set the “New User Default Role” in Settings->General page inside the admin panel.

How can I remove a user role in WordPress?

If you want to remove a WordPress default user role or a role you’ve created yourself, you can use the remove_role function.

remove_role function syntax

The remove_role function will remove a role only with a role name. The only parameter the function gets is $role.

remove_role($role)

the $role parameter is a string value for a role name, the only variable needed to delete a WordPress role.

remove_role function example

For example, we’re going to remove the “Contributor” role from WordPress:

$role = "contributor";
remove_role($role)

Above will work in a custom WordPress plugin or inside the functions.php file of your current theme.

If you do not know how to create a WordPress plugin, I recommend you read my tutorial:

How to create a Hello World plugin for WordPress in 3 Steps

What do you think about "How to Remove a User Role from WordPress (with example)"?

Your rating submit was successfull.

Your rating submit was not successfull.

Menu