Remove WordPress built-in user roles

In case you don’t need and wish to remove WordPress built-in user roles, like ‘subscriber’, ‘contributor’, ‘author’, ‘editor’ this piece of code may delete them for you:

add_action('admin_menu', 'remove_built_in_roles');

function remove_built_in_roles() {
    global $wp_roles;

    $roles_to_remove = array('subscriber', 'contributor', 'author', 'editor');

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

Place it into your active theme functions.php file and open any page of your WordPress site admin back-end. Other way to execute this code is to create file remove-roles.php at the wp-content/mu-plugins folder and insert code above there starting from the <?php at the 1st line.
Do not forget to remove this code/file after the roles will be successfully removed.

Code above removes built-in roles without any concern about if someone was granted access to this role. WordPress looks on a not existed role granted to a user as a user capability granted directly to this user. That is you may see ‘author’ capability granted to this user in a custom capabilities group. So it’s better to revoke unneeded roles from the users before remove those roles.

P.S. I strongly do not recommend to delete the ‘administrator’ role. Some plugins and themes use this role to allow access to the related functionality. You may lose access to them in case your delete this built-in (standard) role.

Generally WordPress does not user role names, it uses/checks user capabilities granted to the roles. But you should be aware of that:
– WordPress Multisite adds user to a new created blog with ‘administrator’ role.
– WordPress Multisite adds user to the 1st blog (from available for this user) with a ‘subscriber’ role, in case primary blog is not defined for this user. Reason – user must have a role at a primary blog.
– If some plugin still uses deprecated user levels (from 0 to 10), then WordPress translates them to the built-in roles from ‘subscriber’ to ‘administrator’.

Share