![](/img/trans.png)
[英]Yii: Getting the role of logged in users and showing content according to role
[英]How Content Only to Logged in Users with Specific role users?
直到现在我找到了这个代码,但这仅适用于登录或未登录。 我也想添加一个角色过滤器。
任何人都可以帮我做吗?
<?php if ( is_user_logged_in() ) : ?>
<My Content>
<?php else : ?>
<Log in to Watch Content>
这是你的答案:
<?php $user = wp_get_current_user();
if ( in_array( 'admin', (array) $user->roles ) ) : ?>
<Your Content>
<?php else : ?>
<Log in to Watch Content>
<?php endif; ?>
你可以做这样的事情。 你不需要做is_user_logged_in()
条件。
<?php
$user = wp_get_current_user();
if ( in_array( 'USER-ROLE', (array) $user->roles ) ) :
// YOUR-CONTENT
else :
// YOUR-CONTENT
endif;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.