php管理员查看用户,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 = "";

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的更多信息.

标签:administrator,php,wordpress

来源: https://codeday.me/bug/20191004/1851753.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值