Home   »   WordPress   »   How to add custom user roles like Guest Author to your WordPress blog

How to add custom user roles like Guest Author to your WordPress blog

share & comment

Ever since WordPress has introduced custom post types and has brought it from just a blogging platform to complete website framework solution, the need of having more user roles than the default ones have emerged. In other words, having same capabilities of a role under different custom names has arisen. This has also become relevant for Multi Author Blogs and Blog Networks. I remember many of the good blogs (ShoutMeLoud, Techiemania etc.) mentioning guest author information in posts submitted by their guest authors. That was something which inspired me to think of a way by which we can have a custom WordPress role like “Guest Author” for a multi author blog or some other type of fancy names having certain capabilities for other sites. After the extension of WordPress CMS capabilities, it is being used for creating websites and other type of web portals. I have recently created a learning portal using WordPress and their having the default WordPress Roles were not enough. Hence I created my custom roles with names which were very specific to that particular solution.

I have already created “Guest Author” Role for my blog ShoutingWords and all the guest contributors are assigned this role. You can also register yourself for the ShoutingWords Revenue Sharing Program and can share your ideas with the world.  Lets see how we can create a custom WordPress role called “Guest Author”.

In this post, I will explain WordPress Roles and will also explain how to create custom user roles for your blog, assign capabilities to a role and do other things related to WordPress Roles. So, let’s get started!

WordPress has multiple user roles like subscriber, contributor, Author, Editor and Administrator with different capabilities. For a detailed list of Role Vs. Capabilities, you can visit this link on WordPress Codex. The lowest possible role with the capability to write a post is contributor, a contributor can write a post but he can not publish it. Usually every guest author on a multi author blog is granted the role of contributor so that an administrator or an editor can check the post and then publish it. What if you want to have the same capabilities as contributor but with a different name and/or you want to add some more capabilities to the contributor role and create a custom role which is specific to your blog or website. Here is how you can do that.

Create a WordPress Custom Role

The WordPress function to create a role is:

<?php add_role($role, $display_name, $capabilities); ?>

To create a role named “Guest Blogger”, you should update the following code in your WordPress Theme’s functions.php file.

/* Add guest author role to the blog */
add_role('guest_author', 'Guest Author', array(
    'read' => true, // True allows that capability
    'edit_posts' => true,
    'delete_posts' => true,
));

The capabilities assigned above are similar to a contributor role but it is now with a different and custom name. If you wish, you can add more capabilities or you can also explicitly restrict this user for a specific capability. Just include any capability in the capabilities array of the above function and give its status true to enable it and false to restrict it.

Assign the Role to users

grey How to add custom user roles like Guest Author to your WordPress blog

Change User Role

To assign the newly create custom role to your blog authors, you should login to your WordPress site admin dashboard. Now go to Users > Users.
Select the check boxes in the left hand side of all the users you want to assign this new role to. Now choose the new role and click on the change button.

I will post more information on how we can create and use custom WordPress roles to bring more life to our WordPress sites, until then do let us know your reactions and feedback about this article.

Enjoyed This Post?

Subscribe to our RSS Feed, Follow us on Twitter or simply recommend us to friends and colleagues!

Subscribe to this blog via Email:

   

{ 4 comments… read them below or add one }

Pulkit Kaushik | TheDolt October 2, 2011 at 3:50 AM

I couldn’t find that code. Guess that was typical only to your theme.
Pulkit Kaushik | TheDolt recently posted..Google Analytics To Now Deliver Stats In Real Time

Reply

jitendra October 2, 2011 at 4:03 AM

Pulkit – Its a WordPress function and is not dependent on any theme. You can use it with any theme. Check out on WordPress Codex http://codex.wordpress.org/Function_Reference/add_role

Reply

Casey Strouse December 27, 2011 at 9:29 PM

Really helpful article. I’ve been working on a project that requires custom roles and custom capabilities and this got me off to a good start. Thanks a bunch.

Reply

jitendra December 27, 2011 at 10:05 PM

Hi Casey – You are welcome. I am glad to know that this helped you. :)

Reply

Leave a Comment

CommentLuv badge

Previous post:

Next post: