2017-05-09 28 views
0

,我有以下我的functions.php函數:WordPress的,如果當前用戶是

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'); 

我想添加其他用戶的角色,但是當我做if (current_user_can('shop_manager', 'shop_assistant'))我得到一個錯誤。

我應該如何添加另一個用戶角色進行檢查?

由於提前,

回答

0

請嘗試

if(current_user_can('shop_manager') || current_user_can('shop_assistant')) 
+0

做了詭計,非常感謝。 – Michel

+0

歡迎:)然後將此標記爲答案,如果有用的投票太:) – Ashkar

0

你可以得到你喜歡這個當前的用戶角色(翻譯)。

然後你可以玩它。

/** 
* 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; 
} 
+0

Ashkars答案將適用於您的應用程序 - 可能會更容易。但有了這個,你可以在任何地方使用它。 – Stender

相關問題