Suppose you need to create a new custom post type, may be NEWS. So that you can allow you subscribers to post NEWS on your website. In the given example we will be creating a custom user role for NEWS and the users allotted this role would only be managing only NEWS section from WP-Admin (Dashboard).
Open your theme’s function.php file: site root >> wp-content >>themes >> function.php and add the given code block:
add_role( ‘news_user’, ‘News User’, array( ‘news’ ) );
This function generates new custom user role which can only manage
news section from Dashboard.
Although you may add some more function for new custom user role.
New custom user role can also be removed from WordPress by using the following function in your theme’s function.php file:
remove_role( ‘news_user’ );
From WordPress Function $wp_roles also you can add and remove custom user roles as show below:
global $wp_roles;
$wp_roles->add_cap( ‘news_user’, ‘manage_category’ );
$wp_roles->remove_cap( ‘news_user’, ‘view_post’ );