Transcript
Introduction
In this lesson, we will learn how to customize user roles using a plugin. Before we create custom roles, let’s remind ourselves of the default roles WordPress provides – Administrator, Editor, Author, Contributor, and Subscriber. We covered these in one of our previous lessons, namely User Management, but the focus for today is custom roles.
Custom roles
But why create custom user roles? Creating custom roles allows you to define specific responsibilities and permissions, segment users and tailor their experiences, manage content moderation effectively, and define custom workflows. Here is a practical example. You might have a non-profit site and have a specific role for coordinators and volunteers. In this example, we’ll create a custom role called “Comment Moderator” for users who can only edit and read posts. Since none of the default roles fit this need, we’ll create a new one using a plugin to show you how it works. There are various plugins to choose from in the Plugins Directory, such as Members, User Role Editor, or Advanced Access Manager.
Using a plugin
In this example, we will install and activate the Members plugin. So once the Members plugin has been installed and activated, we can make our way to Members at the bottom left in the sidebar and then click on “Roles.” Here, we will see all our default roles: Administrator, Author, Contributor, Editor, and Subscriber. The role manager feature allows you to edit and add new roles as well as remove both default capabilities and custom capabilities. Please note that if you make changes to default roles with the plugin, the changes are saved as permanent changes and will need to be reverted using the plugin. If you need to make changes to a default role, it is therefore recommended rather to copy the role and then make the changes in the new role. But we will add a new role called “Comment Moderator.”
Granting permissions
And then you have a wide range of capabilities that you can grant or deny. If none is selected, the user simply won’t have the capability. I will grant the capabilities that I want my Comment Moderator to have. Below General, I will go ahead and grant the Moderate Comments capability. Then, we can make our way to posts and grant all these capabilities, such as reading, editing, publishing, and deleting posts. The next step is to add the role. This all depends on the role that you created and the capabilities that you wanted to assign to that role. So, once you have decided on the role, you can go through all the subheadings and decide which capabilities you want to grant.
Assigning a role
Now, we can go back to roles and see that the Comment Moderator has been added. Next, we will go to Users. On this site, we have two users: the Administrator, which is me, and Don Kamera. So let’s click on Don Kamera, scroll down to the bottom, and then change the user role from Subscriber to Comment Moderator, as we want this person to moderate all the comments that are added to our blog or news page.
Now we can log in as Don Kamera and in the left sidebar we can see that he has very limited capabilities. We can access posts and comments, and as we will notice, we do have a comment waiting for moderation. The comment is clearly not spam so the user can go ahead and approve. Now you can as mentioned duplicate or clone and then customize default roles or you can create new custom roles with limited capabilities.
Resource
Lesson: User management
Practical
Test out a user role plugin using WordPress Playground: