/** * Gets user role name by role slug. * * @see https://wpcodebook.com/wordpress-get-role-name-by-slug/ * @see https://developer.wordpress.org/reference/classes/wp_roles/ */ function wpcodebook_get_role_name( $role ) { $wp_roles = wp_roles(); return ( $wp_roles->roles[ $role ]['name'] ?? $role ); }
Example:
echo wpcodebook_get_role_name( 'shop_manager' );
Output:
Shop manager