Skip to:
Content
Pages
Categories
Search
Top
Bottom

Please make replies not viewable to non-users.


  • cosmiclove1978
    Participant

    @cosmiclove1978

    Dear bbPress-ers!
    Hello. I’m Herman.
    I will greatly appreciate your assistance with a couple of problems with my forum I’ve been trying to fix for a couple of days now with no solution.

    I wanted to display the message “Replies not viewable to non-members” to anonymous/not-logged-in users browsing my forum. This message replaces all actual replies with the generic one above. I was able to achieve this with the code below found on this page Dezzain website. The problem though is that this message shows up everywhere a reply is posted. So if there are 20 replies, there will be 20 generic messages.
    So my request for help #1: I would like the 1 reply ONLY to display the generic message, and the other replies hidden. Any chance you can help me with it please?
    #2, I would like to include a link to register/login in that generic reply. I am not too familiar with php. Can anyone rewrite the message below so that it also has a url portion for “Login here” | Register”?

    Thanks so very much in advance.

    bb_auth_reply_view( 
    $reply_id
    ) {
    $reply_id
    = bbp_get_reply_id( 
    $reply_id
    );
     
    // Check if password is required
    if
    ( post_password_required( 
    $reply_id
    ) )
    return
    get_the_password_form();
     
    $content
    = get_post_field( 
    'post_content'
    , 
    $reply_id
    );
     
    // first topic reply shouldn't be hiding
    $rep_position
    = bbp_get_reply_position(
    $reply_id
    );
     
    // if user is not logged in and not the first post topic
    if
    ( !is_user_logged_in() && 
    $rep_position
    > 1 ) {
    return
    "Replies only viewable for logged in users"
    ;
    } 
    else
    {
    // return normal
    return
    $content
    ;
    }
     
    }
    add_filter( 
    'bbp_get_reply_content'
    , 
    'bb_auth_reply_view'
    );
Viewing 6 replies - 1 through 6 (of 6 total)

  • Robin W
    Moderator

    @robin-w

    the problem is that you are changing the actual content box, so it will still display 20 boxes with author details and only blank the boxes.

    you basically need to alter the bbpress template loop-single-reply.php to achieve what you want

    see

    Step by step guide to setting up a bbPress forum – part 3

    section 3


    cosmiclove1978
    Participant

    @cosmiclove1978

    Hello Robin,

    Thanks for the tip. I checked section 3 of the documentation you suggested. I’ve found the loop-single-reply.php in my theme. I can certainly insert similar file in the child theme.

    Now, thought I get the “what” of your answer, the “How” still eludes me. I’ve been staring at that file for an hour, and I’ve got no clue as to where to place the cursor and what to write if you showed me where to place that cursor in the file.

    The code pasted above in my original post was copied and pasted as is in my Child Theme’s function.php, hoping that it would at least replace actual replies with the generic statement, which it did.

    Will you be so kind as to look at the loop-single-reply.php file below and instruct me how to change the file so that I get the intend result across the forum (for anonymous users, removing/hiding all replies except the first one + original post, and with the 1st reply showing “generic statement + Login | Register” urls)?

    <?php
    
    /**
     * Replies Loop - Single Reply
     *
     * @package bbPress
     * @subpackage Theme
     */
    
    // Exit if accessed directly
    defined( 'ABSPATH' ) || exit;
    
    ?>
    
    <div id="post-<?php bbp_reply_id(); ?>" class="bbp-reply-header">
    	<div class="bbp-meta">
    		<span class="bbp-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    
    		<?php if ( bbp_is_single_user_replies() ) : ?>
    
    			<span class="bbp-header">
    				<?php esc_html_e( 'in reply to: ', 'bbpress' ); ?>
    				<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink( bbp_get_reply_topic_id() ); ?>"><?php bbp_topic_title( bbp_get_reply_topic_id() ); ?></a>
    			</span>
    
    		<?php endif; ?>
    
    		<a href="<?php bbp_reply_url(); ?>" class="bbp-reply-permalink">#<?php bbp_reply_id(); ?></a>
    
    		<?php do_action( 'bbp_theme_before_reply_admin_links' ); ?>
    
    		<?php bbp_reply_admin_links(); ?>
    
    		<?php do_action( 'bbp_theme_after_reply_admin_links' ); ?>
    
    	</div><!-- .bbp-meta -->
    </div><!-- #post-<?php bbp_reply_id(); ?> -->
    
    <div <?php bbp_reply_class(); ?>>
    	<div class="bbp-reply-author">
    
    		<?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    
    		<?php bbp_reply_author_link( array( 'show_role' => true ) ); ?>
    
    		<?php if ( current_user_can( 'moderate', bbp_get_reply_id() ) ) : ?>
    
    			<?php do_action( 'bbp_theme_before_reply_author_admin_details' ); ?>
    
    			<div class="bbp-reply-ip"><?php bbp_author_ip( bbp_get_reply_id() ); ?></div>
    
    			<?php do_action( 'bbp_theme_after_reply_author_admin_details' ); ?>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>
    
    	</div><!-- .bbp-reply-author -->
    
    	<div class="bbp-reply-content">
    
    		<?php do_action( 'bbp_theme_before_reply_content' ); ?>
    
    		<?php bbp_reply_content(); ?>
    
    		<?php do_action( 'bbp_theme_after_reply_content' ); ?>
    
    	</div><!-- .bbp-reply-content -->
    </div><!-- .reply -->
    

    On a separate note, have you developed any BBpress plugin having an upload function not restricted to the media library / where files are retrieved from the user’s local machines directly?

    Thanks in advance for your continued support.
    H


    Robin W
    Moderator

    @robin-w

    This should do what you want

    <?php
    
    /**
     * Replies Loop - Single Reply
     *
     * @package bbPress
     * @subpackage Theme
     */
    
    // Exit if accessed directly
    defined( 'ABSPATH' ) || exit;
    
    ?>
    
    <?php 
    $reply_id = bbp_get_reply_id() ;
    // first topic reply shouldn't be hiding
    $rep_position = bbp_get_reply_position($reply_id);
     
    // if user is not logged in and not the first post topic
    if ( !is_user_logged_in() && $rep_position == 2 ) {
    	echo "<br/><strong>Replies only viewable for logged in users</strong>" ;
    bbp_get_template_part( 'form', 'user-login' );
    } 
    elseif ( !is_user_logged_in() && $rep_position > 2 ) {
    	//do nothing !!
    }
    
    //otherwsie use is logged in and/or this is reply 1 !
    else {
    
    ?>
    
    <div id="post-<?php bbp_reply_id(); ?>" class="bbp-reply-header">
    	<div class="bbp-meta">
    		<span class="bbp-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    
    		<?php if ( bbp_is_single_user_replies() ) : ?>
    
    			<span class="bbp-header">
    				<?php esc_html_e( 'in reply to: ', 'bbpress' ); ?>
    				<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink( bbp_get_reply_topic_id() ); ?>"><?php bbp_topic_title( bbp_get_reply_topic_id() ); ?></a>
    			</span>
    
    		<?php endif; ?>
    
    		<a href="<?php bbp_reply_url(); ?>" class="bbp-reply-permalink">#<?php bbp_reply_id(); ?></a>
    
    		<?php do_action( 'bbp_theme_before_reply_admin_links' ); ?>
    
    		<?php bbp_reply_admin_links(); ?>
    
    		<?php do_action( 'bbp_theme_after_reply_admin_links' ); ?>
    
    	</div><!-- .bbp-meta -->
    </div><!-- #post-<?php bbp_reply_id(); ?> -->
    
    <div <?php bbp_reply_class(); ?>>
    	<div class="bbp-reply-author">
    
    		<?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    
    		<?php bbp_reply_author_link( array( 'show_role' => true ) ); ?>
    
    		<?php if ( current_user_can( 'moderate', bbp_get_reply_id() ) ) : ?>
    
    			<?php do_action( 'bbp_theme_before_reply_author_admin_details' ); ?>
    
    			<div class="bbp-reply-ip"><?php bbp_author_ip( bbp_get_reply_id() ); ?></div>
    
    			<?php do_action( 'bbp_theme_after_reply_author_admin_details' ); ?>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bbp_theme_after_reply_author_details' ); ?>
    
    	</div><!-- .bbp-reply-author -->
    
    	<div class="bbp-reply-content">
    
    		<?php do_action( 'bbp_theme_before_reply_content' ); ?>
    
    		<?php bbp_reply_content(); ?>
    
    		<?php do_action( 'bbp_theme_after_reply_content' ); ?>
    
    	</div><!-- .bbp-reply-content -->
    </div><!-- .reply -->
    
    <!-- end of else!!!-->
    <?php 
    }
    ?>

    BUT be aware this is only hiding replies at this point – there are many ways to see replies in bbpress.


    cosmiclove1978
    Participant

    @cosmiclove1978

    Wow, oh wow, Robin! I don’t know what to say. The timing of it is just…wow

    I thought you had given up on me. So thanks so much for getting back to me with this solution. I’ll try it too.

    I do want to say, however, that in my desperation for a solution, I hired a “developer” on Fiverr to resolve it. Well, it ended quite disappointingly. That guy couldn’t do a single task from adding css to even bothering looking at the php function I posted here earlier. Wasted 2 days and he admitted he’s not familiar with WP. Wait what? We’re now in the Resolution Center as I’ve asked for a full refund.

    So again in desperation, just before receiving your fix, here’s what I did myself with some clunky conditional Logged in/ Logged out css tweaks + the initial php code I posted (the one with all the replies still showing but with a generic message): Post before solution | working CSS solution using initial php function and the css I laboriously came up with.

    /* adding replies message */ 
    
    body:not(.logged-in) li.bbp-body > ul > li:nth-child(2) > div.loop-item--1 > div.bbp-reply-content {
    		border: 1px solid #ffa07a;
        background: antiquewhite;
        padding: 4px!important;
    }
    /* Remove content replies */
    body:not(.logged-in) li.bbp-body > ul > li:not(:nth-child(1)):not(:nth-child(2)) > div.loop-item--1 > div.bbp-reply-content{
    		display:none;
    }
    /*Remove author replies except child 1 and 2 */
    body:not(.logged-in) li.bbp-body > ul > li:not(:nth-child(1)):not(:nth-child(2)) > div.loop-item--1 > div.bbp-reply-author{
    		display:none;
    }
    
    /*Remove header replies for all but child 1 and 2 */
    body:not(.logged-in) li.bbp-body > ul > li:not(:nth-child(1)):not(:nth-child(2)) > div.loop-item--1 > div.bbp-reply-header {
    		display:none;
    }
    /*Remove headers except child (1 & 2) */
    
    body:not(.logged-in) li.bbp-body > ul > li:not(:nth-child(1)):not(:nth-child(2)) > div.bbp-reply-header{
    		display:none;
    }
    /*Remove nested replies */
    body:not(.logged-in) li.bbp-body > ul > li:nth-child(2) > ul > li:nth-child(n+1) > div.loop-item--1 > div.bbp-reply-content{
    		display:none;
    }
    /* Remove author part of nest replies */
    body:not(.logged-in) li.bbp-body > ul > li:nth-child(2) > ul > li:nth-child(n+1) > div.loop-item--1 > div.bbp-reply-author{
    		display:none;
    }
    /*remove header of nested replies 
    
    body:not(.logged-in) #topic-67506-replies > li.bbp-body > ul > li:nth-child(2) > ul{
    		display:none;
    }*/
    
    body:not(.logged-in) li.bbp-body > ul > li > ul.bbp-threaded-replies{
    		display:none;
    }

    It’s quite ugly but did the job, to my own surprise. I was leaving my desk now, and signing off Gmail when I saw your reply. I will give a try and update you. Just a quick question, would you say then that with your fix, it’s still possible for someone to peek at the hidden replies if they know what they’re doing? It’s 2:19AM, i’m fried! So grateful for the assistance. I’ll let you know as soon as I place your solution in my child theme.

    Take care, and ttyl.
    H


    Robin W
    Moderator

    @robin-w

    ok, I should say that I am NOT a bppress author, I am just a user who tries to help others.

    I am author of bbp private groups plugin, which would not help you directly as you want non logged in to see topics, but does mean that I spent a great deal of time locking down bbpress, and knowing where the code displays stuff.

    so for instance my code will not stop searches, access via a users profile, direct entry of urls and many more.

    so if your site needs to seriously hide replies to non logged in, then you would need to hire a very experienced dev. I am trying to retire, so desperately not trying to take on work !!

    I haven’t looked at your solution, and with a smile, will not have time to do this.


    cosmiclove1978
    Participant

    @cosmiclove1978

    It’s all good, Robin. Got it. Just know that I’m still very grateful for your assistance and your time.
    You have a great start of week.
    Cheers,
    H

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar