如何在wordpress插件中获取当前用户相对于角色的权限;如何根据当前用户角色获取权限
如: -
如果输入editor
函数将返回delete_others_posts
,如果输入的是author
结果将是delete_published_posts
等等...提前
如何在wordpress插件中获取当前用户相对于角色的权限;如何根据当前用户角色获取权限
如: -
如果输入editor
函数将返回delete_others_posts
,如果输入的是author
结果将是delete_published_posts
等等...提前
由于获取的名称当前用户角色:
function get_current_user_role() {
global $current_user;
return array_shift($current_user->roles);
}
然后使用get_role($ role_name)func你可以用他所有的能力获得阵列。
EG:$capabilities = get_current_user_role();
另一种解决方案是使用current_user_can($ capability_name)函数返回true或false
对于整个说明:http://tomarea.fr/wordpress-roles-capacites-utilisateurs/
为了详细说明koma182的回答,包get_role()
与var_dump
或print_r
,您将看到当前用户角色的功能:
function get_current_user_role() {
global $current_user;
return array_shift($current_user->roles);
}
,然后在那里你调用该函数:
var_dump(get_role(get_current_user_role()));
感谢救命!
你打算怎么做,你可以进一步解释 – Gowri