Do you wish you could allow your customers, clients, or staff to access your site backend, but you don’t want them to have some capabilities like changing the themes and plugins?
It is possible to create WordPress custom user roles that are specific to your needs.
This is a simple step that does not require you to be an expert WordPress developer; if you can change themes and edit the functions.php file, you can easily and quickly add WordPress custom user roles as I will show you in this tutorial.
Default User Role in WordPress
When you are developing a WordPress membership site, one of the most common things that you need to consider is the different WordPress users and the role they play.
You can also consider using the WooCommerce users function to manage the users on your site especially when you are building an e-commerce website.
How Many Built-In User Roles Does WordPress Have
Fortunately, WordPress comes with six default user roles that have different capabilities and they include:
- Super Admin
- Administrator
- Editor
- Author
- Contributor
- Subscriber
Besides these six default WordPress user roles, we can create unlimited WordPress custom user roles that have unique capabilities.
Users’ Roles and Capabilities
The different WordPress users have different roles and they can perform only what the role capabilities allow them.
For example the lowest role –a subscriber cannot install plugins or themes but can read posts. The editor can edit posts and do much more than what a subscriber and an author can do.
You can learn more about the various roles and capabilities of WordPress users from here.
Creating WordPress Custom User Roles
Since every website has unique needs, you possibly want roles that are different from the default WordPress user roles.
Possibly, you are using WordPress as a content management system and you want to add a custom WordPress role for your staff or clients.
Since we cannot use the default roles we will create the custom user roles by adding a snippet code in the function.php file of the theme.
Alternatively, you can use several plugins that are available for user roles management and they are free to download and install. My favorite free plugin for user roles and capabilities management is the User Role Editor.
Create WordPress User Roles without Using a Plugin
WordPress has the function to add a custom user role that takes three parameters. The function is add_role(); and it takes three parameters
add_role( $role, $display_name, $capabilities );
- $role (string) (required): Unique name of the role
- $display_name (string) (required): The name of the custom user role to be displayed
- $capabilities (array) (optional): Capabilities that the custom role can access
To create a custom user role we will use this function as shown in the code snippet below:
add_role( 'Client', __( 'Client' ), array( 'read'=> true, // true allows this capability 'edit_posts' => true, 'delete_posts' => false, // Use false to explicitly deny 'edit_published_posts' => true, 'publish_posts' => true, 'edit_files' => true, 'import' => true, 'upload_files' => true ) );
Add this code to the functions.php and save the changes.
You can now see the new role and assign new users when you are adding them to your site. Visit the add user page and you should see the new user role as shown in the image below:
Conclusion
Creating WordPress custom user roles is an easy and straightforward process and you can now add the custom user roles that are needed on your website, you can also learn more about the WordPress roles and capabilities to help you in making the custom user role useful.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Comments are closed.