0

I have the following a function in my functions.php:

function admin_style()
{    global $user_ID; 
    if ( current_user_can( 'shop_manager') )
{  wp_enqueue_style('admin-styles', '/wp-content/themes/electa-child/admin.css');
}}
add_action('admin_enqueue_scripts', 'admin_style');

I would like to add another user role but when I do if ( current_user_can( 'shop_manager', 'shop_assistant') ) I am getting an error.

How should I add another user role to be checked upon?

Thanks in advance,

icedwater
  • 4,701
  • 3
  • 35
  • 50
Michel
  • 47
  • 1
  • 7

2 Answers2

0

Please try

   if( current_user_can('shop_manager') || current_user_can('shop_assistant') ) 
Ashkar
  • 712
  • 6
  • 17
0

You can get you current user role (translated) like this.

then you can play around with it.

 /**
 * Returns the translated role of the current user. 
 * No role, get false.
 *
 * @return string The translated name of the current role.
 **/
function get_current_user_role() {
    global $wp_roles;

    $current_user = wp_get_current_user();
    $roles = $current_user->roles;
    $role = array_shift( $roles );

    return isset( $wp_roles->role_names[ $role ] ) ? translate_user_role( $wp_roles->role_names[ $role ] ) : FALSE;
}
Stender
  • 2,446
  • 1
  • 14
  • 22
  • Ashkars answer will work fine for your application - might be easier. but with this, you can use it anywhere. – Stender May 09 '17 at 11:36