php – 检查当前用户是否是wordpress的管理员

我正在为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'  );
}

解决方法:

尝试以下内容:

if ( current_user_can( 'manage_options' ) ) {
    /* A user with admin privileges */
} else {
    /* A user without admin privileges */
}

阅读有关current_user_can函数here的更多信息.

上一篇:快速修改Windows系统密码命令


下一篇:内网渗透(常用工具使用介绍)