Adding and deleting custom WordPress User Roles

By default, WordPress comes with five different user roles: subscriber, contributor, author, editor,  and Administrator. If you are in need of adding more admin roles, You can use the WordPress add_role() built-in function or install the User Role Plugin plugin. Apart from adding different user roles, this plugin will also let you assign different capabilities to each role.

If you are comfortable with coding you would better avoid using plugins while you can achieve the same results with just a few lines of code.

The snippet below will help you add a custom user role to your WordPress website. In this example, we are adding a new user role named ‘Translator’. To use the snippet, just place it in your functions.php file and change the instances of ‘Translator’ with the editor’s name you wish to add.

// Adding a new wordpress user role named 'Translator'
add_role('translator', 'Translator', array(
    'read' => true,
    'edit_posts' => true,
    'delete_posts' => true,
    'edit_published_posts' => true,
    'publish_posts' => true,
    'edit_files' => true,
    'import' => true,
    'upload_files' => true

You can give your custom user roles different capabilities. If you need more details make sure to check the WordPress official documentation about the user roles function.

Keep in mind though that the code snippet should be executed only one time and then you will need to comment it or even delete it from your functions.php file. Once this function is run it registers a new user role in your WordPress database with all your specified privileges.

In case you want to delete a user role from your database you can run the following function. In our case, we are removing the previously added user role ‘Translator’.  Make sure to replace it with your the exact user role you want to delete.

//Delete the user role 'Translator'