How to Add Custom User Roles on Your WordPress Site

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 is different. For example, Subscriber user role has only read capability whereas Contributor has different capabilities, such as read, delete posts and edit posts.

To learn about WordPress user roles, you can read this article.

WordPress User Roles, Permissions and Capabilities Explained

In this article, We are going to discuss why custom user role is necessary and how to add a custom user role.

Creating Custom User Roles on Your WordPress Site

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 with capabilities.

There are two major ways of creating custom user roles in WordPress. You can do it by adding custom code or by using a plugin. We will discuss both of the approaches in this post. Let’s see how they work.

Plugin Method: Using A WordPress Custom User Role Plugin

You may like to use 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.

Creating a New User Role

  • After installing and activating this plugin navigate to wp-admin → Users → Add New Role
  • 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.

Now, go to wp-admin → Settings → General, click on New User Default Role dropdown field. You can see 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!

Custom Code Method

WordPress is the number one CMS in the world and it is popular for its open source nature. This means you have the opportunity of customizing WordPress the way you want and its completely FREE. Just like that WordPress gives you the opportunity to create custom user role by using a function called add_role();

There are three parameters in add_role() function.

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

  1. $role (string) (required): Unique name of the role
  2. $display_name (string) (required): The name to be displayed
  3. $capabilities (array) (optional): Capabilities that one can access

Let’s create a new user role named Custom Editor with read and edit posts capabilities. Include the following lines of code toward the end of your functions.php, which is located in your theme folder.


add_role(
    'custom_editor',
    __( 'Custom Editor' ),
    array(
        'read'         => true,  // true allows this capability
        'edit_posts'   => true,
    )
);

Now save the file, login 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 WordPress admin panel, also you can set this role as New User Default Role.

We hope this tutorial will be very helpful for beginner users. If you have any suggestions or query, please let us know in the comments.

9 Comments

  • Alejandro

    Alejandro

    Hello, very good article, I would like to know how I can change the name of a role already created, for example I have to Vendor that I simply want to change the language and pass it to Spanish since neither poedit nor crazy helped me to solve it. it would only be that, some code so that I can locate it in funtions of my child theme, for example I have a code that is function wpbod_nombres_roles () {

    global $ wp_roles;

    if (! isset ($ wp_roles)) {
    $ wp_roles = new WP_Roles ();
    }

    $ wp_roles-> roles [‘contributor’] [‘name’] = ‘Participant’;
    $ wp_roles-> role_names [‘contributor’] = ‘Participant’;

    $ wp_roles-> roles [‘subscriber’] [‘name’] = ‘Honorary’;
    $ wp_roles-> role_names [‘subscriber’] = ‘Honorary’;

    }
    add_action (‘init’, ‘wpbod_nombre_roles’); but the vendor roles for example do not change it or pendig seller. thank you very much for your help.

  • Rabbi

    Rabbi

    Hello Alejandro,

    You can use WP User Role Renamer plugin to rename user role. Here is the download link: https://wordpress.org/plugins/wp-user-role-renamer/

    Thanks

  • צלם אירועים

    צלם אירועים

    Thank you for the information

  • Samuel

    Samuel

    Yes that’s what I was looking to create custom user role for my wordpress site with having different roles.
    Thanks to you for writing about it. Cheers!

  • Tomas Ale

    Tomas Ale

    Thanks

  • công ty bất động sản

    công ty bất động sản

    Really no matter if someone doesn’t be aware of then its up to other users that they will assist,
    so here it takes place.

  • Pingback: WordPress User Roles, Explained under 5 min!

  • halfey

    halfey

    I wonder if I could create 2 user roles with the same set of privileges (capabilities), let’s say “Readers A” and “Readers B” where I can set “Articles A” only available to Readers A, and likewise “Articles B” only visible to Readers B, despite both groups have the same privileges.

  • Daniel

    Daniel

    Really that’s good job. Thanks to you!
    This is very helpful article for those who are interested in WordPress. Actually I’m interested to make career in WordPress. Recently I have purchased WordPress hosting coupon with discount offer. But I face difficulty to create custom user role and searching about this. I found your article and you have provided this solution with interface. I’m getting more help from your article.

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.