How To Create Custom User Roles In WordPress

What are WP user roles? How to use, apply customize and create new custom user roles for your WordPress site purposes and activities easily.

By Claudio Pires
Updated on July 25, 2022
How To Create Custom User Roles In WordPress

Understand what is WordPress user roles, how to use, apply customize and create new custom user roles for your site 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. In addition, many WordPress users don’t know that they can limit their access to Dashboard. Moreover, creating new custom user roles helps to make sure that only specific groups of people have access to just the areas they need. So, 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
How To Create Custom User Roles In WordPress

Understanding User Roles of WordPress:

A User Role is the combination of two things.

  1. Firstly, Role
  2. Secondly, Capabilities

The 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. Firstly, Super Admin: Profile that has access to the complete website, including network administrative features.
  2. Secondly, Administrator: Profile that has all administration features.
  3. Editor: Profile that can create, edit, and publish their and other posts too.
  4. Author: Profile that can create, edit, and publish their own posts only.
  5. Contributor: Profile that can create, and edit their own posts only but cannot publish them.
  6. Finally, 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”.

Moreover, You can see current user roles like the image below.

Navigate to “Users > All Users”. How To Create Custom User Roles In WordPress

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. So, modify and delete user roles and capabilities. But, I would recommend the User Role Editor plugin.

Here is what you can do using this plugin.

Plugin To Modify WordPress 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 the role and its capabilities.

Removing Default User Roles:

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

Navigate to “Appearance > Editor > Theme functions How To Create Custom User Roles In WordPress

As a result, we’ll use a WordPress function:

  • remove_role(): To remove a custom user role.

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

1 remove_role( ‘subscriber’ );
2 remove_role( ‘editor’ );
3 remove_role( ‘contributor’ );
4 remove_role( ‘author’ );

Click on “Update File”.

remove_role(): To remove a role.

To verify the deleted user roles.

Navigate to “Users > All Users”.

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

Navigate to “Users > All Users”.

Creating Roles:

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

  1. Firstly, the Administrator: Will have complete administrative access.
  2. Secondly, moderators: Can create, edit, and publish their and other’s post too.
  3. Finally, Newbie: He 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 the add_role function.

add_role( $role, $display_name, $capabilities );

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

A 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, and publish his own and others’ posts too.

Copy” below code and “Paste” it at the end of your “Theme Functions” file to create a custom user role.

 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 on “Update File”.

rights to create, edit, and publish How To Create Custom User Roles In WordPress

Assign “Moderator” Role to a User:

From the WordPress Admin Panel. So, Navigate to “Users > All Users” and follow the instructions below.

Assign “Moderator” Role to a User:

We’ve assigned the “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 the right to just edit his profile and create new posts using the custom user roles.

Copy” below code and “Paste” it at the end of your “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, click on “Update File” like the below image.

Theme Functions file How To Create Custom User Roles In WordPress

Assign “Newbie” Role to a User:

Firstly, from the WordPress Admin Panel,

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

Navigate to “Users > All Users

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

Posts add new WordPress dashboard

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

assign the “Newbie” role
Claudio Pires

Claudio Pires is the co-founder of Visualmodo, a renowned company in web development and design. With over 15 years of experience, Claudio has honed his skills in content creation, web development support, and senior web designer. A trilingual expert fluent in English, Portuguese, and Spanish, he brings a global perspective to his work. Beyond his professional endeavors, Claudio is an active YouTuber, sharing his insights and expertise with a broader audience. Based in Brazil, Claudio continues to push the boundaries of web design and digital content, making him a pivotal figure in the industry.