Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Create and Manage Custom User Roles in WordPress

March 27, 2019

7 Min Read
WordPress User Roles
Reading Time: 7 minutes

WordPress has been a popular option for websites that need a content management system. Like other CMS, WordPress provides comprehensive predefined user roles that fulfill the requirements of website administrators and managers.

Most of the users don’t know that they can assign WordPress user types and limit access to the dashboard for specific users. This action ensures that only a specific group of users have access to specific admin panel areas and options. Custom WordPress user roles also help minimize the chances of any accidents that can bring down the whole website.

In this article, I will describe two ways of creating WordPress new user roles using a plugin and ensure that everything on your website is under control.

Understanding WordPress User Roles

In WordPress, a User Role is a combination of:

  1. Role
  2. Capabilities

A role is the name of a user group that will be displayed in your WordPress Admin Panel and capabilities are the privileges that admins can enable or disable.

By default, WordPress has 6 basic user roles.

  1. Super Admin: The profile that has access to the entire website including network administrative features.
  2. Administrator: The profile(s) that has all administrative privileges.
  3. Editor: The profile(s) that can create, edit, publish their and other users’ posts.
  4. Author: The profile(s) that can create, edit, publish their own posts only.
  5. Contributor: The profile(s) that can create, edit their own posts but cannot publish them.
  6. Subscriber: The profile(s) that can only manage their own profiles.

You can find your WordPress user right within your dashboard.

Log in to your WordPress Admin Panel, navigate to Users → All Users.

You can see the current user roles available on your website:

change user

Getting Ready to Create New User Roles

There are two ways to create, edit or delete user roles in WordPress.

1. Modify WordPress User Roles via Plugin

Sometimes a plugin that can control user roles in WordPress offers the simplest solution. There are lots of plugins for adding, modifying and deleting user roles and capabilities. I would suggest trying out the User Role Editor plugin.

Once installed and activated, from the left pane, navigate to Users → User Role Editor.

update-optoins

As you can see, there are a lot of options to add/modify/delete.

First of all, notice that you can see all the user roles that exist on your WordPress site.  If you want to update or change anything, select the user role from the list.

user editor role

In my case, I have chosen the Editor role and marked where it says Granted Only you can see the existing capabilities assigned to the Editor.

Editor Limited Access

If you are unfamiliar with WordPress access levels and capabilities of a role, give this WordPress Codex a read to understand them in detail.

User Role Editor allows you to rename the capabilities by checking the box.

editor user role

And here is how the capabilities will be renamed in human-readable form.

Editor Limited Access

Ok so now you have got an idea how the plugin lists existing capabilities assigned to each WordPress user role.

To increase WordPress user capabilities, you can go to the respective group from the left side. For example, in addition to the current capabilities, I also want to allow Editor to Add and Activate plugins.

For this, navigate to Plugins group from the left pane and select Install Plugins, and Activate Plugins and update the user by clicking the Update button on the right.

Now visit the Granted Only section and you will see that the Editor can now Install and Activate plugins.

To add (or remove) capabilities for a specific user role, navigate to the respective group from the left pane and assign (or remove) the capabilities accordingly.

Create a New WordPress User Role
User Role Editor also allows you to create new Roles besides the administrator, author, editor, etc. Click on the Add Role button from the right menu, and a new popup will appear asking you:

  • Role Name (ID): A unique ID for each user role.
  • Display Role Name: The name of the role that will be displayed.
  • Make Copy of: Select the existing role that would form the basis of the new role.

add role

In my case, I have copied the Editor role and named the new role as Editor Limited Access. You can see, the new role has all the same capabilities as that of the original editor role.

editor limited access

Now, I can add/remove capabilities for this new role.

Just like adding a role, you can also add/create new capabilities and assign them to any WordPress user role.

Next, I will demonstrate how you can create custom WordPress user roles via code.

2. Create, Edit or Delete WordPress User Roles Manually

WordPress allows you to remove the default user roles and create custom user roles by assigning limited privileges/capabilities to specific user groups (Roles).

WordPress provides five functions for managing roles and capabilities:

  • add_role(): For adding a custom role.
  • remove_role(): For removing a custom role.
  • add_cap(): For adding a custom capability to a role.
  • remove_cap(): For removing a custom capability from a role.
  • get_role (): Gets information about the role and its capabilities.

Remove Default User Roles
I will start by removing the existing roles. Remember that WordPress, by default, has the following five roles:

  1. Subscriber
  2. Editor
  3. Contributor
  4. Author
  5. Administrator

For the purpose of this tutorial, I will remove all user roles except the Administrator. For this, navigate to WordPress Admin → Appearance → Editor → Theme functions.

function php file

I will use remove_role() to remove the role. Copy the following code snippet and paste it at the end of the Theme Functions file.

remove_role( 'subscriber' );
remove_role( 'editor' );
remove_role( 'contributor' );
remove_role( 'author' );

Click the Update File button.

update file

To verify that the user roles have been deleted, navigate to Users → All Users.

You can see that except for administrator, all default user roles have been deleted.

administrator
Create New User Roles
For the purpose of this tutorial, I will create three new user roles.

  1. Administrator: with complete administrative access.
  2. Moderator: That can create, edit, publish their and other users’ posts.
  3. Newbie: That can only edit their profile and create new posts.

To add these custom user roles, I will use the native add_role() function with the following syntax:

add_role( $role, $display_name, $capabilities );
  1. $role: A unique name of the role.
  2. $display_name: The name to be displayed in the WordPress Admin Panel.
  3. $capabilities: Privileges of the role.

A complete list of all capabilities can be found here.

Administrator

Since I didn’t delete the default administrator role, all the capabilities and privileges of the role are intact.

Moderator

This role has the rights to create, edit, publish their own and other users’ posts.

Copy the following code and paste it at the end of the  Theme Functions file.

add_role('moderator', __(

   'Moderator'),

   array(

       'read'            => true, // Allows a user to read

       'create_posts'      => true, // Allows user to create new posts

       'edit_posts'        => true, // Allows user to edit their own posts

       'edit_others_posts' => true, // Allows user to edit others posts too

       'publish_posts' => true, // Allows the user to publish posts

       'manage_categories' => true, // Allows user to manage post categories

       )

);

Click Update File.

update file
Assign “Moderator” Role to a User
Next, I will assign this role to a user. For this navigate to WordPress Dashboard → Users → All Users and follow the instructions below.

modiator

I have assigned Moderator role to the user “Alex”. You can see (from the image below) that when he logs in and goes to “Dashboard”, he will have limited access as per the capabilities of his new role.

add-new-post

Newbie

This role can just edit their profile and create new posts.

To add this role, copy the following code and paste it at the end of the Theme Functions file.

add_role('newbie', __(
'Newbie'),
array(
'read' => true, // Allows a user to read
'create_posts' => true, // Allows user to create new posts
'edit_posts' => true, // Allows user to edit their own posts
)
);

After pasting the code, click the Update File button.


Assign “Newbie” Role to a User
For assigning the new role to a user, navigate to WordPress Dashboard → Users → All Users and follow the instructions below.

add user

I have assigned a Newbie role to the user “Dicaprio”. You can see ( from the image below) that when he logs in and goes to Dashboard, he’ll have limited privileges.

Now, I will assign the Newbie role to every visitor who registers on my website.

add-new-post

Now, I will assign the Newbie role to every visitor who registers on my website.

Wrapping up!

In this article, I have explained to you how to create users on WordPress and what are the various types and permissions to choose from. As you have seen, there are many customization options, and you have a very large margin of actions that you can make available or not for each of your users.

What WordPress user privileges you’ve enabled on your platform? Share your experience with us by leaving a comment in the box below.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Start Growing with Cloudways Today!

We never compromise on performance, security, and support.

Mustaasam Saleem

Mustaasam is the WordPress Community Manager at Cloudways - A Managed WordPress Hosting Platform, where he actively works and loves sharing his knowledge with the WordPress Community. When he is not working, you can find him playing squash with his friends, or defending in Football, and listening to music. You can email him at mustaasam.saleem@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!