admin管理员组文章数量:1414604
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
also evaluates to false when using current_user_can('delete_site');
My wordpress install is hosted on my local machine, Lubuntu 18.04 with apache2. Php 7.2. I can access the site by navigating to http://localhost/folderName
in Google Chrome.
I have cookie auth enabled and see my user cookie is present with the EditThisCookie Chrome extension.
In the xdebug console (of Phpstorm 2019.2) I also get a false response:
current_user_can('delete_site');
false
current_user_can('administrator');
false
I have no issues navigating around the front or back end of the wordpress site as an Admin. I feel like this might be an environment issue due to the discrepency betwen the Chrome experience and what the plugin and Xdebug are catching.
Does anyone know why I am running into this issue?
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
also evaluates to false when using current_user_can('delete_site');
My wordpress install is hosted on my local machine, Lubuntu 18.04 with apache2. Php 7.2. I can access the site by navigating to http://localhost/folderName
in Google Chrome.
I have cookie auth enabled and see my user cookie is present with the EditThisCookie Chrome extension.
In the xdebug console (of Phpstorm 2019.2) I also get a false response:
current_user_can('delete_site');
false
current_user_can('administrator');
false
I have no issues navigating around the front or back end of the wordpress site as an Admin. I feel like this might be an environment issue due to the discrepency betwen the Chrome experience and what the plugin and Xdebug are catching.
Does anyone know why I am running into this issue?
Share Improve this question asked Sep 1, 2019 at 17:45 Sean DSean D 3878 silver badges21 bronze badges 4 |1 Answer
Reset to default 1Normally for checking for administration privileges you have to check the “manage_options” capability, such as:
current_user_can('manage_options')
Alternatively, you want to list the roles with wp_get_current_user()->roles and ensure the “Administrator” role is in that array.
The capabilities you are checking for do not exist in a vanilla install of wp.
本文标签: rest apicurrentusercan(39administrator39) returns false when I39m logged in
版权声明:本文标题:rest api - current_user_can('administrator') returns false when I'm logged in 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194242a2647059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
rest_api_init
– Sean D Commented Sep 2, 2019 at 11:25