Understand what is WordPress user roles, how to use, apply customize and cerante new rules for you site user purposes and activities in an easy way.

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.

 

How To Create 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.

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 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.

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”.

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.

remove_role( ‘subscriber’ );
remove_role( ‘editor’ );
remove_role( ‘contributor’ );
remove_role( ‘author’ );

Click on “Update File”.

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.

Creating 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”.

Assign “Moderator” Role to a User:

From the WordPress Admin Panel.

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

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.

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.

Assign “Newbie” Role to a User:

From the WordPress Admin Panel,

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

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.

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