Function — Add or rename user roles - martindubenet/Wordpress GitHub Wiki

https://wordpress.org/support/article/roles-and-capabilities/

Capability key Administrator Editor Author Contributor Subscriber
activate_plugins
customize
delete_others_pages
delete_others_posts
delete_pages
delete_posts
delete_private_pages
delete_private_posts
delete_published_pages
delete_published_posts
delete_site
edit_dashboard
edit_others_pages
edit_others_posts
edit_pages
edit_posts
edit_private_pages
edit_private_posts
edit_published_pages
edit_published_posts
edit_theme_options
export
import
list_users
manage_categories
manage_links
manage_options
moderate_comments
promote_users
publish_pages
publish_posts
read
read_private_pages
read_private_posts
remove_users
switch_themes
upload_files

Administrator Editor Author Contributor Subscriber
activate_plugins
customize
delete_others_pages
delete_others_posts
delete_pages
delete_posts
delete_private_pages
delete_private_posts
delete_published_pages
delete_published_posts
delete_site
edit_dashboard
edit_others_pages
edit_others_posts
edit_pages
edit_posts
edit_private_pages
edit_private_posts
edit_published_pages
edit_published_posts
edit_theme_options
export
import
list_users
manage_categories
manage_links
manage_options
moderate_comments
promote_users
publish_pages
publish_posts
read
read_private_pages
read_private_posts
remove_users
switch_themes
upload_files
delete_others_pages
delete_others_posts
delete_pages
delete_posts
delete_private_pages
delete_private_posts
delete_published_pages
delete_published_posts
edit_others_pages
edit_others_posts
edit_pages
edit_posts
edit_private_pages
edit_private_posts
edit_published_pages
edit_published_posts
manage_categories
manage_links
moderate_comments
publish_pages
publish_posts
read
read_private_pages
read_private_posts
unfiltered_html
upload_files
delete_posts
delete_published_posts
edit_posts
edit_published_posts
publish_posts
read
upload_files
delete_posts
edit_posts
read
read

Functions

Rename an existing role

function rename_existing_role() {
    global $wp_roles;

    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles();

    $wp_roles->roles['contributor']['name'] = __('Sales Clerk', 'MyTheme');
    $wp_roles->role_names['contributor'] = __('Sales Clerk', 'MyTheme');
}
add_action('init', 'rename_existing_role');

Add a custom user role

add_role(
	'voluntary_worker',
	__( 'Voluntary Worker', 'MyTheme' ),
	array(
		'read'         => true
	)
);
⚠️ **GitHub.com Fallback** ⚠️