protected function isAdmin() : bool {
$check = current_user_can(\'administrator\');
return $check;
// returns false as I am logged in as superadmin, refreshing the page for xdebug to run
}
$check 使用时也计算为false
current_user_can(\'delete_site\');我的wordpress安装托管在本地机器Lubuntu 18.04和apache2上。Php 7.2。我可以通过导航到访问该网站http://localhost/folderName 在Google Chrome中。
我已启用cookie身份验证,并看到我的用户cookie与EditThisCookie Chrome扩展一起存在。
在xdebug控制台(Phpstorm 2019.2)中,我还得到一个错误的响应:
current_user_can(\'delete_site\');
false
current_user_can(\'administrator\');
false
作为管理员,我在wordpress网站的前端或后端导航都没有问题。我觉得这可能是一个环境问题,因为Chrome体验与插件和Xdebug所捕获的内容之间存在差异。
有人知道我为什么会遇到这个问题吗?
最合适的回答,由SO网友:santamanno 整理而成
通常,要检查管理权限,您必须检查“manage\\u options”功能,例如:
current_user_can(\'manage_options\')
或者,您希望列出具有wp\\u get\\u current\\u user()->角色的角色,并确保“Administrator”角色位于该数组中。
您正在检查的功能在普通wp安装中不存在。