如何限制未注册的用户在wordpress中的某些内容或页面

时间:2014-09-30 12:45:29

标签: php wordpress wordpress-plugin wordpress-theming wordpress-login

我正在开发一个带有wordpress的网站,该网站在照片库和一些教程视频页面中有一个评论区域。如何限制未登记的用户发表评论和进入视频页面。直到我有很多谷歌,但没有得到任何与我的问题相关的解决方案。我已经搜索了很多插件,但没用, 对于注册我使用饼状寄存器插件我的word-press主题是抛物线。  我试图在主题文件夹中的comment.php文件中进行一些更改:

<?php
    /**
     * The template for displaying Comments.
     *
     * The area of the page that contains both current comments
     * and the comment form. The actual display of comments is
     * handled by a callback to tc_comment_callback()
     *
     * @package Customizr
     * @since Customizr 1.0
     */

    /*
     * If the current post is protected by a password and
     * the visitor has not yet entered the password we will
     * return early without loading the comments.
     */
     if ( have_comments() )
         echo apply_filters( 'tc_comment_separator', '<hr class="featurette-divider '. current_filter() .'">' );
?>

     <div id="comments" class="<?php echo apply_filters( 'tc_comments_wrapper_class' , 'comments-area' ) ?>" >
<?php 
     if( is_user_logged_in() )
     {
         comment_form( array( 'title_reply' => __( 'Leave a Comment' , 'customizr' ) ) );
         if ( have_comments() )
         do_action ( '__comment' );
      }
?>
    </div><!-- #comments .comments-area -->

1 个答案:

答案 0 :(得分:0)

只需在!之前加is_user_logged_in()

例如:

if( !is_user_logged_in() ) {
    // Content shown for non-users
}

if( is_user_logged_in() ) {
    // Content shown for authorized users
}
相关问题