User roles has been an essential part of the WordPress always.
a lot of users even do not know that they can create WordPress custom user roles expect those default roles and with limit obtain users for particular features of your WordPress site.
User roles are what allows the user to check which actions other users on your WordPress website can execute and what content or attribute those users have to enter to. By default, WordPress one site comes with six roles, but lots of plugins are used for extra user roles, and you’re also generating your user roles.
In this WordPress article, we are going to tell you the custom ways of generating WordPress new user roles.
In WordPress, a User Role is a mixture or group of:
- Role
- Capabilities
Each role on your WordPress website explain the unique capabilities that an account with that specific role can execute.
WordPress previously has six prescribed roles that you can see after installing a fresh WordPress to your domain or localhost. These are Super Admin, Administrator, Author, Editor, Contributor, and Subscriber. Every user role has different features and privileges. Like, the Author role has Edit, the Subscriber user role has only read capability, Publish and Upload files and Contributor has diverse capabilities, like that read, delete and edit posts.
Now when we create custom user role you need to concentrate on do two things which are
- Generate the role
- Allocate capabilities to that generated role
Generating Custom User Roles on Your WordPress website
Now you used add_role() function to generate new roles in your WordPress website.
Here, are three parameters in add_role()function.
add_role(#role,#display_name,#capabilities);
#role is the unique name, #display_name is the display name, #capabilities is the features one can access
In this step add this small code at the bottom of your Functions.php which is in your theme folder.
add_role(
‘wp_coder',
__( ‘wp_coder' ),
array(
‘read' => true, // true allows this features or capability
‘edit_posts' => true,
'create_posts' => true,
'edit_pages' => true,
)
);
Next step limiting the new user for access some,capabilities
 you need to do only this user
add_role(
‘wp_coder',
__( ‘wp_coder' ),
array(
‘read' => true, // true allows this features or capability
‘edit_posts' => true,
'create_posts' => true,
'edit_pages' => true,
'edit_themes' => false, // false denies this features or capability.
'install_plugins' => false,
)
);
Next, save the file, login to your worpdress admin site, then go to Settings page then click on the General page. You can see the newly generated user role in the list of the user.
Also read: How to Restrict WordPress Admin Access by IP address
We hope this WordPress tutorial will be very useful for a beginner.
0 Comments