Wordpress

How to delete default user roles

How to Delete WP User Roles

There are many reasons to have several user roles on your WordPress site that you don’t need or don’t want. Maybe you decided to try a new user system that you’ve now dropped. Or maybe you’ve installed a plugin or a specialized theme that automatically created new user roles. Plugins or themes that create roles often let you delete those roles, maybe you uninstalled them so long ago you can’t even remember what created them in the first place. In this article, we are going to show how to delete WordPress roles and WordPress default user roles.

There two ways to delete WordPress user roles

  1. By installing the User Role Editor
  2. By adding a Code Snippet to your Active theme’s function.php file.

 

1.User Role Editor

User Role Editor WordPress plugin allows you to edit user roles and capabilities easily. Just turn on the checkboxes of capabilities you wish to add to the selected user role and click the “Update” button to save your setting changes. Add new roles and customize its capabilities according to your requirements, from scratch as a copy of other existing user roles. An unnecessary self-made role can be deleted if there are no users whom such role is assigned. The role assigned every newly created user by default may be changed too.

2.By adding a Code Snippet to your Active theme’s function.php file.


add_action('admin_menu', 'remove_built_in_roles');

function remove_built_in_roles() {
global $wp_roles;

$roles_to_remove = array('author', 'editor', 'contributor', 'event-manager', 'wpseo_editor', 'wpseo_manager','employer' );

foreach ($roles_to_remove as $role) {
if (isset($wp_roles->roles[$role])) {
$wp_roles->remove_role($role);
}
}
}

 

Place it into your active theme’s functions.php file and open any page of your WordPress site admin back-end and anyone front end page then the above code will be executed and the default roles will be deleted which you have mentioned the array.

Note:  I strongly do not recommend to delete the ‘administrator’ role. Some plugins and themes use this role to allow access to the related theme functionalities. You may lose access to them in case if you are deleting this WordPress built-in (standard) role. smart home

Happy Coding 🙂

About the author

Chetan Hegde

Chetan Hegde

Chetan Hegde is the architect of ProCodersOnline.com. I'm a Software Engineer and technology enthusiast person who loves to learn and explore new things and technologies. When i'm not writing content for my websites, I love to travel and explore the nature.

Add Comment

Click here to post a comment