[英]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.