How to Add Custom User Roles in WordPress

by Mustaasam Saleem  March 9, 2017

Like other Content Management Systems, WordPress has predefined User Roles that fulfill the basic needs of a CMS. Many WordPress users don’t know that they can limit the access of Dashboard. By creating new custom user roles, it helps to make sure that only specific groups of people have access to just the areas they need. It would help to minimize the chances of any accidents happening that can bring down the whole website. Today, we’ll learn how we can create new custom user roles manually and through a plugin.

custom-user-roles-in-wordpress

Understanding User Roles of WordPress:

A User Role is the combination of two things.

  1. Role
  2. Capabilities

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

By default, WordPress has 6 basic user roles.

  1. Super Admin: Profile that has access to the complete website, including network administrative features.
  2. Administrator: Profile that has all administration features.
  3. Editor: Profile that can create, edit, publish their and other posts too.
  4. Author: Profile that can create, edit, publish their own posts only.
  5. Contributor: Profile that can create, edit their own posts only but cannot publish them.
  6. Subscriber: Profile that can manage their own profiles only.

You can find current user roles within your WordPress Admin Panel.

Login to your “WordPress Admin Panel”.

Navigate to “Users > All Users”.

You can see current user roles like the image below.

WordPress Custom User Roles

Getting Ready to Create New User Roles:

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

1. Plugin To Modify WordPress User Roles:

Sometimes you want to use a plugin that can control User Roles in WordPress. There are lots of Plugins available to add, modify and delete user roles and capabilities. But, I would recommend User Role Editor plugin.

Here is what you can do using this plugin.

WordPress Custom User Roles

But, this article is mainly focused on the manual method.

2. Create, Edit or Delete WordPress User Roles Manually:

WordPress allows you to remove its default user roles and create your own custom user roles by assigning limited privileges to specific user groups.

Today, we’ll teach you how you can remove and create new user roles manually.

There are five functions for managing roles and capabilities:

  • add_role(): To add a custom role.
  • remove_role(): To remove a custom role.
  • add_cap(): To add a custom capability to a role.
  • remove_cap(): To remove a custom capability from a role.
  • get_role (): Gets information about role and its capabilities.

Removing Default User Roles:

First of all we will remove the existing WordPress Default User Roles. In our tutorial we have 5 user roles.

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

Remove all user roles except “Administrator”.

From your WordPress Admin Panel.

Navigate to “Appearance > Editor > Theme functions”.

da

We’ll use a WordPress function:

  • remove_role(): To remove a role.

Copy” below code and “Paste” it at the end of your “Theme Functions” file.

Click on “Update File”.

WordPress Custom User Roles

To verify the deleted user roles.

Navigate to “Users > All Users”.

You can see except administrator all default user roles are deleted in the image below.

WordPress Custom User Roles

Creating User Roles:

In our tutorial, we’ll create three new user roles.

  1. Administrator: That will have complete administrative access.
  2. Moderator: That can create, edit, publish their and other’s post too.
  3. Newbie : That can only edit his profile and create new posts.

To add our own user roles we’ll use a WordPress function.

  • add_role(): To add a custom role.

There are three parameters in add_role function.

  1. $role: Unique name of the role.
  2. $display_name: The name to be displayed in WordPress Admin Panel.
  3. $capabilities: Privileges that one can access.

Complete list of all capabilities can be found here.

1. Administrator:

We didn’t delete the default administrator. That’s why, we’ll leave it with default privileges.

2. Moderator:

As we’ve already discussed, we’ll give him rights to create, edit, publish his own and other’s posts too.

Copy” below code and “Paste” it at the end of your “Theme Functions” file.

Click on “Update File”.

WordPress Custom User Roles

Assign “Moderator” Role to a User:

From the WordPress Admin Panel.

Navigate to “Users > All Users” and follow instructions below.

WordPress Custom User Roles

We’ve assigned “Moderator” role to our user “Alex”. You can see from the image below that when he logs in and goes to “Dashboard”, he’ll be having limited access that we’ve allowed him.

1

3. Newbie:

As we’ve already discussed, we’ll give him rights to just edit his profile and create new posts.

Copy” below code and “Paste” it at the end of your “Theme Functions” file.

After pasting, click on “Update File” like below image.

2

Assign “Newbie” Role to a User:

From the WordPress Admin Panel,

Navigate to “Users > All Users” and follow instructions below.

3

We’ve assigned “Newbie” role to our user “Dicaprio”. You can see from the image below that when he logs in and goes to “Dashboard”, he’ll be having limited access that we’ve allowed him.

4

Now, we’ll assign the “Newbie” role whenever a visitor registers.

5

 

Conclusion

By following the above tutorial, you can create custom user roles for any WordPress based website. Let me know if you have any issues in creating custom user roles by using the comments section below.

Additionally, keep an eye on this blog as I will be adding more resources for WordPress in the coming weeks. Likewise, you can start working by creating custom user roles using the method stated above or plugin that I’ve recommended and let me know what more features you want unlocked in it. 

Make Your WordPress Website 100% Faster.

Host it now on Cloudways WordPress Hosting Platform.

About 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

Stay Connected:

You Might Also Like...