Wordpress 如何根据当前用户角色获取权限
如何在wordpress插件中获得当前用户与其角色相关的权限 例如:- 如果输入是Wordpress 如何根据当前用户角色获取权限,wordpress,plugins,Wordpress,Plugins,如何在wordpress插件中获得当前用户与其角色相关的权限 例如:- 如果输入是编辑器函数应返回删除其他帖子,如果输入是作者结果将是删除发布的帖子,依此类推 提前感谢获取当前用户角色的名称: function get_current_user_role() { global $current_user; return array_shift($current_user->roles); } 然后使用get_role($role_name)函数可以获得一个具有其所有功能的数组
编辑器
函数应返回删除其他帖子
,如果输入是作者
结果将是删除发布的帖子
,依此类推
提前感谢获取当前用户角色的名称:
function get_current_user_role() {
global $current_user;
return array_shift($current_user->roles);
}
然后使用get_role($role_name)函数可以获得一个具有其所有功能的数组
例如:$capabilities=get_current_user_role()代码>
另一种解决方案是使用返回true或false的current_user_can($capability_name)函数
对于完整的解释:要详细说明koma182的答案,请使用var\u dump
或print\u r
包装get\u role()
,您将看到当前用户角色的功能:
function get_current_user_role() {
global $current_user;
return array_shift($current_user->roles);
}
然后调用函数的位置:
var_dump(get_role(get_current_user_role()));
谢谢Koma 你能进一步解释一下吗