While using a WordPress website, an admin may encounter to select a user’s role which means the admin can assign specific user control level. There are six different pre-defined user roles: Super Admin, Administrator, Editor, Author, Contributor, and Subscriber. Each of them has a different set of tasks and capabilities.

For Example, Super Admin has full control over the WordPress website and users while Subscriber only has the capability of reading posts.

There are so many possibilities of user roles depending upon what kind of users you want on your website. In these cases, creating appropriate user roles is helpful. You can add custom user role as you need by two methods either by code or by plugins. Let’s take a look at both of them one by one.

Custom Coding Method

WordPress has open-source nature so it is possible to integrate our own custom codes to add user roles as we want. WordPress provides a function add_role() which accepts three arguments :

add_role( string $role, string $display_name, array $capabilities = array() );

$role (string) (Required) Role name.

$display_name (string) (Required) Display name for role.

$capabilities (array) (Optional) List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );

Now you would have to paste the following link in your functions.php file in your theme folder.

function wbcom_custom_roles() {
if ( get_option( 'custom_roles_version' ) < 1 ) {
add_role( 'custom_role', 'Custom Subscriber', array( 'read' => true, 'level_0' => true ) );
update_option( 'custom_roles_version', 1 );
}
}
add_action( 'init', 'wbcom_custom_roles' );

And it’s all set and done. Now you can see your custom created user role in Admin Dashboard > Settings > General.

In the above code, we wrapped add_role() function into another function called wbcom_custom_roles() which checks and ensures the user role is created only one time and doesn’t update the database every time the website loads.

You can also add or modify the role in the array() argument of add_role() function. Some examples could be, ‘edit_posts’ => ‘true’ or ‘delete_posts’ => ‘false’ or ‘administrator’ => ‘true’ etc.

Plugin Method

You may also consider using a plugin for it if you don’t like to add custom code to your theme. To do so, we are using the “User Role Editor” plugin which is a great user role and management plugin.

— Go to your Admin Dashboard, install and activate this plugin.

— Now navigate to Users > User Role Editor

— Here you can add/delete user roles or edit already existing roles.

— After creating a User Role you should see it in Settings > General Tab.

 

Wrapping Up

Words at last, as you can see it’s not very difficult to create your custom user roles through code or plugins. From these methods, you can control each and every user without any complications and uncertainty.

If you have any problem in implementing any of these methods to add custom user roles, you are always welcome to ask in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ending Soon
00 Days
00 Hrs
00 Mins
00 Secs
Expired
April Fever Stay Safe 😷😷- Get 25% off on all plugins & themes.
Coupon : AprilFever

Wbcom Designs