Wo​​rdpress如果当前用户是

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

我想添加另一个用户角色, 但是当我执行if(current_user_can(‘shop_manager’, ‘shop_assistant’))时, 出现错误。

我应该如何添加另一个要检查的用户角色?

提前致谢,


#1


请试试

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

#2


你可以像这样获得当前的用户角色(翻译)。

然后你可以尝试一下。

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

来源:

https://www.srcmini02.com/66174.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?