Search

How to Add a Custom Role in WordPress (Without Plugin)

Not everyone who manages website content needs to have administrative privileges. Therefore, we need to assign each user a role based on need. It’s a great security measure and can better ensure against mishaps or even someone binge-installing random or dangerous plugins.

There are some built-in user roles in WordPress ready to use, from the most privileges to the website management to the least are:

  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber.

We will show you each role’s capabilities in a table, but not all capabilities are listed as WordPress has lot more capabilities. However, it’s a good way for an overall understanding of what each user role can or can’t do.

You can learn more about the various role capabilities that WordPress offers.

But while the default user roles are useful, there are times when you need those extra capabilities for a specific role. Large organizations may have several different types of content, with specific people in mind to manage each one. In this case, a default user role wouldn’t be ideal. For example, you need the capabilities of the Author role with the ability to moderate comments on their own posts. And that’s what we will do.

In this article, we will show you how to create a custom user role without any plugin. We will create a custom user role named “Author Pro” for demonstration. It will include all capabilities of the author role with the additional ability to moderate the comments on their own posts.

Step 1: Open the Theme Function(function.php)

Firstly, go to Appearance → Theme File Editor on the WordPress dashboard, it will take you to the Edit Themes page, go to Theme Files section and select Theme Functions(function.php).

Now we will use the following snippet to create a custom user role and set the capabilities of the newly created role. Let’s insert the snippet under the opening PHP tag( <?php).

/* Create Author Pro User Role */
add_role(
    'author_pro', //  System name of the role.
    __( 'Author Pro'  ), // Display name of the role.
    array(
        'read'  => true,
        'delete_posts'  => true,
        'delete_published_posts' => true,
        'edit_posts'   => true,
        'publish_posts' => true,
        'edit_published_posts'   => true,
        'upload_files'  => true,
        'moderate_comments'=> true, // This user will be able to moderate the comments.
    )
);

After the snippet is in place, click the Update File button, viola new role was created successfully.

Step 2: Create a New User with Custom Role

Let’s create a new user, by going to User → Add New. On the Roles option, our newly created role will be visible and ready for selection.

After the new user is created, let’s get a look at how it works for comment moderation.

Step 3: Test the Custom Role

Before we go further, let’s make the comment require approval to appear in the post. To make it so, from the WordPress dashboard go to Settings Discussion Before a comment appears, tick the box of the Comment must be manually approved setting.

Onto the Comments menu item on the dashboard, we already have 2 comments waiting for approval. Let’s approve those comments.

As you can see on the above GIF animation, we can give moderation only to the comments in the posts that we created. That way each user using our custom role will have the freedom to moderate and interact with all the comments on their own posts.

The Bottom Line

While the default user roles are useful, there are times when you need those extra capabilities for a specific role. For example, you need the capabilities of the Author role with the ability to moderate comments on their own posts. And that’s what we did in this article.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment