首页 > 解决方案 > 如何仅向具有特定角色用户的登录用户提供内容?

问题描述

直到现在我找到了这个代码,但这仅适用于登录或未登录。我也想添加一个角色过滤器。

任何人都可以帮我做吗?

<?php if ( is_user_logged_in() ) : ?>
<My Content>
<?php else : ?>
<Log in to Watch Content>

标签: phphtmlwordpress

解决方案


这是你的答案:

<?php   $user = wp_get_current_user();
    if ( in_array( 'admin', (array) $user->roles ) ) : ?>
       <Your Content>  
    <?php else : ?>
    <Log in to Watch Content>
<?php endif; ?>

推荐阅读