User role is meant to allow user to perform multiple tasks. WordPress offers number of user roles and allows different users to access different sections of websites. This is one of the key feature which is often overlooked by users. These user roles can help you to insure that only few people have access to just the areas where they want to. Restricting access to certain areas helps you in minimizing the chances of any misuse that can cause any serious damage to any WordPress website.
Since user roles have become an important part in WordPress from the release of WordPress version 2.0, many WordPress user don’t know that they can limit the user access of the dashboard. WordPress comes with six pre-defined different user roles :
WordPress allows you to add new user roles using PHP giving you the freedom to arrange those roles accordingly. For instance, you may want a user to create / edit posts, manage categories, edit pages and more importantly it is equally necessary for them to avoid few things like edit themes, update core, and add or remove plugin.
WordPress doesn’t offer any kind of inbuilt graphic interface for creating roles. There is an easiest way to add roles in WordPress by using PHP function that allows you to specify exactly what permission to assign to an user.
The function to add user with custom permissions is “add_role”.
This function takes three parameters as follows :
A detailed explanation of this function can be found at WordPress codex
Take a look at the following function that we often use to create a user type “Client” that has access to all the features but plugin management. Just copy paste the following code in your theme’s functions.php file.
$result = add_role( 'clients', __('Clients' ),
'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode'edit_themes' => false, // false denies this capability. User can’t edit your theme
'edit_files' => true,
'install_plugins' => false, // User cant add new plugins
'update_plugin' => false, // User can’t update any plugins
'update_core' => false // user cant perform core updates
We hope this article was useful for you and helped you with creating your own custom user type 🙂
Press 💚 below and join the other 13,000+ getting valuable updates from this blog.
Want us to analyze your site first and then use our services? No worries. Just fill out the form to the right and we will be happy to send you a free report about your current website.