Hello to all, welcome to therichpost.com. In this post, I will tell you, How to create new user role in WordPress and add capability to that role?
WordPress is the best part for me in developer websites.
We will create new user role like “administrator” with wordpress custom functionality. We will create “employee” user role and we will also add capability like edit post, add post etc.
Here is the code and you need to add this code in your theme’s functions.php file:
function add_theme_caps() { add_role( 'employee', __( 'Therichpost Employee' ), array( 'read' => true, // true allows this capability 'edit_posts' => false, 'delete_posts' => false, // Use false to explicitly deny 'manage_options' => false ) ); // gets the author role $role = get_role( 'employee' ); // add capability to the author role $role->add_cap( 'view_dashboard' ); } add_action( 'admin_init', 'add_theme_caps' );
This is it, if you have any query related to this post or you want any kind information related wordpress then please let me know.
Jassa jatt
Thank you
Recent Comments