Hide comment feature if not logged in

  • heinohund

    #8409

    Hi There,

    I wish for a feature there can hide the ability to read or write comments on a post if user i not logged in.

    Best regards

    Henrik

    Anonymous

    #41090

    WordPress Dashboard –> Settings –> Discussion Settings –> Other comment settings and check Users must be registered and logged in to comment .

    Anonymous

    #41091

    Moved to support since the feature is already there in WordPress core.

    heinohund

    #41092

    But what i want is to hide the comment if not logged in.

    The standard WP only hide the write option not the read option

    Anonymous

    #41093

    Add this to child-theme functions.php and let me know if it works,

    <?php
    /**
    * Helps to determine if the comments should be shown.
    * This function has been edited to hide comments if the user is not logged in.
    */
    function graphene_should_show_comments() {
    global $graphene_settings, $post;
    if ( ! isset( $post ) ) return;

    if ( $graphene_settings['comments_setting'] == 'disabled_completely' )
    return false;

    if ( $graphene_settings['comments_setting'] == 'disabled_pages' && get_post_type( $post->ID ) == 'page' )
    return false;

    if ( ! is_singular() && $graphene_settings['hide_post_commentcount'] )
    return false;

    if ( ! comments_open() && ! is_singular() && get_comments_number( $post->ID ) == 0 )
    return false;

    if ( !is_user_logged_in() )
    return false;

    return true;
    }

    heinohund

    #41094

    Do i just make a copy of the functions.php and place it in the childfolder?

    Or do i past into blank finctions.php and place it in chilfolder?

    Anonymous

    #41095

    No, no. Don’t copy the entire functions.php file to child theme. Create a blank functions.php and add the above code.

    You can download the child theme template from my site. Link is in my signature.

    heinohund

    #41096

    I allready have a childtema 🙂

    I try make a new freesh functions.php

    heinohund

    #41097

    I think it’s working 🙂

    You are a genius!!

    I’ll put in my main site tomorrow!!

    Thanks!

    BR

    Henrik

    heinohund

    #41098

    And working in prduction as well 🙂

    Thanks again!

    BR

    Henrik

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!