The Roles and Capabilities in WordPress are a powerful tool to allow different users to do things in WordPress, or to prevent them from doing things. But they are also hard to understand, especially as a developer trying to customize them. When you introduce a custom post type, create dashboard panels, or offer some other functionality that should only be available for some user roles, adding your own capabilities is the recommended way. But what if site owners need to change them? This is where a plugin like User Role Editor is needed.
What does User Role Editor do?
As the name says: it allows you to edit user roles and their capabilities. You can add capabilities to existing roles, create new roles or clone existing ones (to then change them). A user in WordPress can usually only have one role, but with this plugin, you can assign multiple roles to them.
The plugin also has a pro version, but I never really looked into it, since I use it only for small manipulations on the roles and capabilities of WordPress installations. In the past, I’ve also used the Members plugin, which had a similar feature set, but then changed into a larger membership plugin, which I didn’t need.
What do I use User Role Editor for?
On one website where I use Koko Analytics (which I wrote about in a previous blog post), the person responsible for the site, does not have the administrator role. Since statistics are only visible to administrator users, I had to change the roles and capabilities. I could have allowed the editor role to view statistics, by giving them the view_koko_analytics capability, but instead I’ve created a “Koko Analytics Viewer” role with that one capability and assigned it to the user. I usually try not to change the default roles from WordPress, since those changes might get overwritten.
Conclusion
If you want to change the roles and capabilities in WordPress, the User Role Editor is one of the easiest ways to do that. As a developer, you can also use the “Roles API” with functions like add_role(), to make these type of changes. I also like to use the WP-CLI and its wp role command, but you may not be able to use the CLI on a website (like I can’t in my example), and using a plugin like User Role Editor still allows you to easily change things. After you’ve done making changes, you can also often remove the plugin, since roles and capabilities are stored in the database. But if you want to keep the UI to assign a user to multiple roles, just leave the plugin installed and activated.
So, I think User Role Editor could fit for me. I was just wondering if it could be possible to show content to newsletter subscribers only.
But I feel that I might need the pro version as, among others, it shows these features:
Shortcode to show enclosed content to the users with selected roles only.
Posts and pages view restrictions for selected roles.
But I’ll check for the free version first. Using Full Site Editor I doubt it could work on the menu. I have the whole holidays of time.