Discover in this tutorial how to create a new custom WordPress user role without plugins, using code.
By default, WordPress has 5 user roles:
In addition to these, some Plugins can add new roles. For example, WooCommerce creates two more:
- Store Manager
WordPress has the following feature that makes the process easier:
Snippet to create a custom WordPress user role
To generate a new user role you can use the native function of add_role(), which has the following syntax:
add_role( $role, $display_name, $capabilities );
- $role: Unique name of the role.
- $display_name: Name displayed in the WordPress administration panel.
- $capabilities: Privileges of the role.
Add the following code at the end of functions.php or in your functionality plugin:
With this fragment you create a new role with the name “Subscriber +” that has the ability to do the same as another subscriber plus create and edit their own posts.
This is just an example, but you can play with all the capabilities that WordPress allows. To learn about them all, take a look at their documentation on Roles and Capabilities.
Another interesting option would be to give that new user profile access to restricted web content. This can be done easily by combining the creation of a new profile with the Restrict Content Pro plugin.
Now you know how to generate a custom WordPress user role, without plugins, with a simple code snippet.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉