As your WordPress website expands, the default user roles may only partially align with your needs. Whether you’re running a membership site, an eCommerce platform, or a content-heavy blog, creating custom user roles in WordPress can be highly beneficial.
With six predefined roles and their respective capabilities, you may need to create custom roles to suit your requirements. So, Let’s get started.
Type of Default User Roles in a WordPress Site
Before creating custom user roles, you must know about WordPress’s default user roles.
-
Administrator
The Administrator role commands the highest access and control over a WordPress site. Administrators can oversee all aspects of the site, including installing plugins, creating and editing content, managing user accounts, and modifying site settings. They can control the site’s functionality and execute administrative tasks.
-
Editor
Editors can create, edit, publish, and delete their own content and content created by other users. They can also manage and moderate comments, create categories and perform editorial tasks. However, editors do not have access to sensitive site settings or the ability to install plugins or themes.
-
Author
Authors can create, edit, publish, and delete their posts. They have control over their 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.
-
Contributor
Contributors have the privilege to write and submit their posts for review. However, they do not have the authority to publish them. Once submitted, their posts must receive approval from an editor or administrator before publication. Contributors are restricted from modifying or deleting posts created by other users and have limited access to site settings.
-
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 leave comments on posts, but they cannot create or edit content. Subscribers are primarily used for user registration and membership purposes.
-
Super Admin
WordPress’s ‘Super Admin’ role is exclusively available for managing multisite networks within a single umbrella network. The Super Admin possesses all of an Administrator’s permissions and can make network-wide changes, including adding or removing sites and configuring themes, plugins, and more.
Importance of Custom User Roles in WordPress
Before delving into the process of creating a custom user role, it’s essential to understand the reasons behind its necessity.
-
Fine-Grained Permissions
By creating custom user roles, you have the power to define granular permissions at a more detailed level.
-
Content Moderation
Creating a custom user role is essential for effective content moderation when your application involves user-generated content.
-
Various Pricing Tiers or Subscriptions
For applications offering multiple pricing tiers or subscription plans, custom user roles are essential for enforcing access restrictions based on the user’s subscription level.
-
Role-Based Access Control (RBAC)
RBAC allows you to create various user roles according to their responsibilities and permissions.
-
User Segmentation
Custom user roles allow you to effectively segment your user base and deliver personalized experiences tailored to their specific roles.
-
Custom Workflows
A custom user role empowers you to define your application’s custom workflows or business processes.
Now, it’s time to discuss how to create custom user roles for your WordPress site.
How to Add Custom User Roles in WordPress
If you want a user, who can only edit posts and read, but none of the six default user roles offer this specific combination of capabilities, the best solution is to create a custom user role and assign the desired capabilities.
Adding the edit posts capability to the subscriber using the add_cap() function is not recommended. There are two main ways to create custom user roles in WordPress.
- Using a plugin, add a custom user role.
- By using custom code, add a custom user role.
Now, let’s discuss one-by-one
1. Using a Plugin, Add a Custom User Role
Consider using a plugin instead of adding custom code. The Members plugin is a famous user and role management plugin designed to enhance WordPress as a CMS.
You can install the plugin from your WordPress dashboard by navigating to WP-Admin >> Plugins >> Add New and searching for the plugin name. After activation, you can access all available roles and add new ones using the Members plugin.
Add a Custom User Role
Go to wp-admin >> Members >> Add New Role after installing and activating this plugin.
Now, put the role title (Comments Moderator)
Choose the capabilities for the new user role (moderate comments, read)
Press on the Add Role button.
Assigning the New User Role
To assign a new user role, navigate to WP-Admin >> Users. Select a user and assign the new role from the drop-down box.
Assigning the New User Role as Default
Now, navigate to WP-Admin >> Settings >> General, and select the New User Default Role dropdown field. You can view and assign the newly created user role from the list of default user roles.
Creating a custom user role in WordPress is a breeze with this handy plugin. It only takes a few simple steps.
Updating a User Role
This plugin can be used to edit an existing user role or create a new custom role. Simply go to WP-Admin and then to Members. You will see the Edit option when you hover over your selected user role.
Please note that you can also find the delete option to remove any user role.
Tick or untick the capabilities, then press the “Update” button.
2. By using Custom Code, Add a Custom User Role
WordPress is the most popular CMS worldwide and is well-known for being open-source. This means you can customize WordPress as you see fit, and it’s completely free. With WordPress, you can create a custom user role using the add_role() function.
The CMS offers five functions for managing WordPress roles and capabilities.
- add_role(): To add a custom role.
- remove_role(): To remove a custom role.
- add_cap(): This adds 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.
add_role() function has three parameters:
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 define a new user role called “Moderator” with the ability to read, create, and publish posts. To do this, add the following lines of code to the end of your functions.php file, which is located in your theme folder.
You can insert the code using Appearance >> Theme File Editor.
Now, you can view how it looks like
You can see the new user role in the WP-Admin >> Users
Save the file, log in to your site with an admin account, and go to Settings >> General. The newly created user role will appear in the user list.
Assign a user to this role from the WordPress admin panel, and set this role as the default for new users. That’s all.
Removing a User Role Using Code
To remove a user role, simply use the remove_role() function.
Now press the update button
You can see the user role has been removed.
Conclusion
In conclusion, Using built-in functions or plugins provides flexibility and ease of implementation, ensuring that even users with limited technical knowledge can effectively create and manage custom roles.
Customizing user roles and regularly reviewing and adjusting permissions to maintain a secure and efficient environment. This deliberate approach not only enhances user experience but also significantly contributes to the overall effectiveness of your WordPress site.
Leave a Reply