wordpress设置隐藏内容指定用户级别可见

来自:互联网
时间:2023-01-06
阅读:

今天给大家分享wordpress网站如何设置指定用户级别查看内容的方法。

wordpress用户的默认等级如下,根据这个等级代码调用就可以了:

管理员:Administrator: level 10

编辑:Editor: Level 7
作者:Author: Level 4
投稿者:Contributor: Level 2
订阅者:Subscriber: Level 0
访客: Level 在 0 以下

管理员可见可以用下面的代码:

<?php global $user_ID; if( $user_ID ) : ?>
<?php if( current_user_can('level_10') ) : ?>
管理员可见的内容<?php endif; ?>
<?php endif; ?>

如果要按照用户等级显示不同内容就可以用下面的代码:

<?php if (current_user_can('level_10')) : ?>
管理員可见内容
<?php elseif (current_user_can('level_7')) : ?>
編輯可见内容
<?php elseif (current_user_can('level_4')) : ?>
作者可见内容
<?php elseif (current_user_can('level_2')) : ->
投稿者可见内容
<?php elseif (current_user_can('level_0')) : ?>
订阅者可见内容
<?php else : ?-->
一般访客可见内容
<?php endif; ?-->
返回顶部
顶部