【发布时间】:2013-11-17 02:58:37
【问题描述】:
我正在为 wordpress 开发一个插件,我想知道当前用户是否是管理员,不幸的是我无法使用 current_user_can(),因为它给了我错误,所以我使用全局 $current_user。但即使是管理员用户,我也无法进入 if 部分。如何解决这个问题?
global $current_user;
if ($current_user->role[0]=='administrator'){
function hide_post_page_options() {
//global $post;
// Set the display css property to none for add category and add tag functions
$hide_post_options = "<style type=\"text/css\"> .jaxtag { display: none; } #category-adder { display: none; } </style>";
print($hide_post_options);
}
add_action( 'admin_head', 'hide_post_page_options' );
}
【问题讨论】:
-
错误是什么,您要检查什么?您使用的是当前版本的 wp 吗?例如,current_user_can('manage_sites') 适用于超级管理员。也许你传递了一个无效的权限
-
出现致命错误:当我使用 current_user_can 时,在第 1286 行的 /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-includes/capabilities.php 中调用未定义函数 wp_get_current_user()。
-
你搜索过
Check if current user is administrator in wordpress吗? -
如果您在管理面板中,is_admin() 很有用。但是,如果您只想检查角色,则不是-尽管现在我回顾一下这个问题,他似乎正在添加管理员 css,所以您可能是对的
标签: php wordpress administrator