As your WordPress website grows and evolves, the default user roles provided by WordPress may not fully align with your requirements.
Whether you're running a membership site, an eCommerce platform, or a content-heavy blog, if you have the ability to create WordPress custom user roles, you will be benefited in many ways.
WordPress has six predefined roles: Super Admin, Administrator, Editor, Author, Contributor, and Subscriber. Each role is allowed to perform a set of tasks called Capabilities. That means capabilities for each type of role are different.
Now if you want to create any custom role other than these 6 default roles, you should follow this blog. In this tutorial, we are going to show you how to create custom roles in a WordPress site. So, without any further ado, let's get started!
Understanding 6 Default User Roles in a WordPress Site
Before you go and create any custom user roles, you need to know about the default user roles of WordPress. The user roles are-
01. Administrator
The Administrator role has the highest level of access and control over the WordPress site. Administrators can manage all aspects of the site, including installing plugins, creating and editing content, managing user accounts, and modifying site settings.
They have full control over the site's functionality and can perform any administrative tasks.
02. Editor
Editors have the ability to create, edit, publish, and delete their own content, as well as content created by other users. They can manage and moderate comments, create categories and perform various editorial tasks.
However, editors do not have access to sensitive site settings or the ability to install plugins or themes.
03. Author
Authors can create, edit, publish, and delete their own posts. They have control over their own content and can manage comments on their posts. However, authors cannot modify or delete content created by other users, and they do not have access to plugins or site settings.
04. Contributor
Contributors can write and submit their own posts for review but cannot publish them. Once submitted, their posts must be approved by an editor or administrator before they are published. Contributors cannot modify or delete posts created by other users and have limited access to site settings.
05. Subscriber
Subscribers have the most limited access among the default user roles. They can log in to the site and update their profile information. Subscribers can also leave comments on posts, but they do not have the ability to create or edit content. Subscribers are primarily used for user registration and membership purposes.
06. Super Admin
You will get this ‘Super Admin’ role available on your WordPress site only when you are managing multisite networks in one umbrella network. Super Admin will get all the permissions that the Administrator gets.
And in addition, they can make changes on the network like can add or remove any sites from the network, and configuring any changes to themes, plugins, or more.
If you want to know more about the WordPress user roles, you can check our blog-
The Ultimate Guide to WordPress User Roles and Permissions
Why Custom User Roles in WordPress is Important
Before we go into how to create a custom user role, we need to understand why it is necessary to create one-
- Role-Based Access Control (RBAC)-With RBAC, you can define different user roles based on their responsibilities and permissions.
- Fine-Grained Permissions – By creating custom user roles, you can define granular permissions at a more detailed level.
- User Segmentation- Custom user roles enable you to segment your user base and provide tailored experiences based on their roles.
- Content Moderation – If your application involves user-generated content, a custom user role can be useful for content moderation purposes
- Custom Workflows – A custom user role allows you to define custom workflows or business processes within your application.
- Different Pricing Tiers or Subscriptions – If your application offers different pricing tiers or subscription plans, custom user roles can help enforce access restrictions based on the user's subscription level.
Now, let's see how you can create custom user roles for your WordPress site.
How to Create WordPress Custom User Roles- 2 Ways for You
Suppose, you want to have a user who can only edit posts and read, but among the six default user roles, you will not find a single one who has only read and edit posts capabilities but more or less. In this case, what’s the solution?
You may add edit posts capability for the subscriber by using add_cap(); function, but this is not a good practice. The best idea is to create a custom user role by assigning them capabilities.
There are two major ways of creating custom user roles in WordPress.
- Create a custom user role using custom code
- Create a custom user role using a plugin
We will discuss both approaches in this post. Let’s see how they work.
01. How to Add, Edit, & Delete a New User Role in WordPress Using a Plugin
You may like to use a plugin instead of adding custom code. To create new user roles you can use Members plugin, it is a very popular user and role management plugin that was created to make WordPress a more powerful CMS.
You can easily install the plugin from your WordPress dashboard. Just go to WP-Admin–>Plugins–> Add New. There type the plugin name and activate the plugin. Now let's see how to add a new role using the Members plugin.
After activating the plugin, you can see all the available roles,
1. Creating a New User Role
- After installing and activating this plugin navigate to wp-admin → Members → Add New Role
- Now, enter the role title (e.g Comments Moderator)
- Select the capabilities for this new user role (e.g. moderate comments, read)
- Click on Add Role button.
2. Assigning the New User Role
In order to assign a new user role, go to WP-Admin–> Users. Choose a user and assign the new role from the drop-down box,
3. Assigning the New User as Default User Role
Now, go to WP-Admin → Settings → General, and click on New User Default Role dropdown field. You can see and assign the newly created user role listed along with the default user roles.
It's very easy, right? Using this handy plugin, we have created a WordPress custom user role and it took only a few steps!
4. Editing a User Role
With this plugin, you can edit an existing user role or the new custom role as well. Just go to WP-Admin–> Members. If you hover over your selected user role, you will find the Edit option.
Note: You can find the delete option as well if you want to remove any user role.
Now, check or uncheck the capabilities and then click on the Update button.
This is how you can edit or delete a user role using the plugin.
02. How to Add and Delete a User Role in WordPress Using Custom Code
WordPress is the number one CMS in the world and it is popular for its open-source nature. This means you have the opportunity to customize WordPress the way you want and it's completely FREE.
Just like that WordPress gives you the opportunity to create a custom user role by using a function called add_role();
The CMS provides five functions for managing WordPress 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.
There are three parameters in add_role()
function.
add_role( $role, $display_name, $capabilities );
- $role (string) (required): Unique name of the role
- $display_name (string) (required): The name to be displayed
- $capabilities (array) (optional): Capabilities that one can access
Let’s create a new user role named Moderator with read, create and publish posts capabilities. Include the following lines of code toward the end of your functions.php, which is located in your theme folder.
You can add the code by navigating to Appearance–> Theme File Editor.
add_role('moderator', 'Moderator', array(
'read' => true,
'create_posts' => true,
'edit_posts' => true,
'edit_others_posts' => true,
'publish_posts' => true,
'manage_categories' => true,
));
Here's how it looks like-
You will find the new user role in the WP-Admin–> Users section,
Now save the file, and log in to your site with an admin account. Navigate to Settings → General. You can see the newly created user role in the user list.
That’s all, you can assign a user to this role from the WordPress admin panel, also you can set this role as New User Default Role.
Removing a User Role Using Code
In order to remove a user role, just use the remove_role() function.
remove_role( 'subscriber' );
remove_role( 'editor' );
remove_role( 'contributor' );
remove_role( 'author' );
After that, click the update button,
You will see that the roles have been removed.
This is how you can add and remove roles using custom code.
We hope this tutorial will be very helpful for beginner users. If you have any suggestions or queries, please let us know in the comments.
If you want you can check out this video as well-
Most Common FAQs on WordPress Custom User Roles
01. Is there a way to control whether an editor has access to only specific categories?
Yes, you can control and set your editors’ capabilities. There are some plugins in the WordPress repository to manage Editors’ capability or you can fix the editor role from your dashboard by selecting the ‘screen options’ just below the boxes feature.
02. How to manage user roles and permissions in WordPress?
Here's how you can manage user roles and permissions in WordPress-
- Understanding User Roles
- Accessing User Roles and Permissions
- Assigning User Roles
- Customizing User Permissions
- Creating Custom User Roles
- Testing User Roles.
03. Is it possible to create different types of Administrators?
Yes, it is possible to create different types of administrators with varying levels of access and permissions. Here's how you can create different types of administrators with specific backend access.
- Regular Administrator: This would be the default administrator role with full access to all features and functionalities within the dashboard.
- Membership Administrator: To create a Membership Administrator role with backend access limited to the membership plugin, you would need to define a custom user role specifically for this purpose. This custom role would have the necessary permissions and capabilities to manage the membership plugin while restricting access to other areas of the dashboard.
- Plugin-Specific Administrator: Similarly, for creating an administrator with backend access to a different plugin but no access to other areas, you would need to define a custom user role for this purpose. The custom role would be granted permissions and capabilities related to the specific plugin, while restrictions are applied to prevent access to other parts of the dashboard.
04. Is there a way to control whether an editor has access to only specific categories?
Yes, you can control and set your editors’ capabilities. There are some plugins in the WordPress repository to manage Editors’ capability or you can fix the editor role from your dashboard by selecting the ‘screen options’ just below the boxes feature.
05. How to create a technical role but restrict Publishing rights and User management rights?
To create a technical role that restricts publishing rights and user management rights, you can follow these general steps:
- Identify the Requirements: Determine the specific permissions and capabilities that the technical role should have. Make a list of the functionalities that the role needs access to and those that should be restricted.
- Create a Custom User Role: Utilize a plugin or implement custom code to create a custom user role with the desired name for the technical role. This can be done using WordPress'
add_role()
function or through a plugin that offers role management functionality. - Define Role Capabilities: Specify the capabilities that the technical role should have. You can use WordPress'
add_cap()
function or a role management plugin to assign capabilities to the custom user role. Ensure that the capabilities assigned to the role do not include publishing rights or user management rights. - Restrict Publishing Rights: To restrict publishing rights, remove the capabilities associated with publishing and editing content. This can include capabilities such as
publish_posts
,edit_posts
,delete_posts
, and other related capabilities. This ensures that the technical role cannot publish or modify content on the website. - Restrict User Management Rights: To restrict user management rights, remove the capabilities associated with managing users, such as
create_users
,edit_users
,delete_users
, and other relevant capabilities. This prevents the technical role from adding, modifying, or deleting user accounts. - Test and Refine: Test the custom role by logging in with a user assigned the technical role and verify that the desired restrictions are in place. Make any necessary adjustments to the role's capabilities to ensure that it aligns with your requirements.
06. How to create 2 user roles with the same set of privileges
It is possible to create two user roles with the same set of privileges (capabilities) but restrict access to specific content for each role. Here's how you can achieve that:
- Create Two Custom User Roles: Using a plugin or custom code, create two custom user roles named “Readers A” and “Readers B”. Assign the same set of privileges (capabilities) to both roles. This ensures that both roles have the same level of access and capabilities within the system.
- Restrict Access to Specific Content: To make “Articles A” available only to “Readers A” and “Articles B” visible only to “Readers B”, you need to implement content restrictions based on user roles. This can be done using plugins or custom code.
- Test and Verify: After implementing the content restrictions, thoroughly test the system to ensure that “Articles A” are only accessible to “Readers A” and “Articles B” are only visible to “Readers B”. Login with different user accounts assigned to each role and verify that the desired content restrictions are in place.
Create a Custom User Role For a WordPress Site the Right Way!
We are at the end of our article and we have shown two ways to create a custom user role-
- Using a plugin
- Using custom code.
Now it is up to you to decide which way you prefer. If you are sure about your technical skills then you should try the custom code method. But if you don't have the time and are not sure about your technical abilities then you should use the plugin method.
If you have any questions regarding the methods, do leave your questions in the comment section.