Home » WordPress Tutorials » You are reading »

BBPress: How to hide replies from not logged in users

hide-bbpress-forums-repliesSetting up discussion forums with your WordPress is easy with WordPress plugin BBPress. By default, all forums, topics and replies created are made public, means all visitors can view all topic and reply made by your community. Even though as admin, you could choose to make your forums into ‘private’ forums with BBPress own forums settings but how about hiding BBpress topics replies from your none logged in visitors or not logged in members in open public forums topics?

Actually its quite easy, you just need to add this add_filter() code into your functions.php

function 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' );

Check this before and after adding the code

please note: the first reply is the main question or topic created, as you can see, the second reply will be hidden from not logged in users.

Hiding BBpress replies? Why?

Sometime when you have a premium/paid support forums for your product, you need to hide your answers or replies from not logged in visitors. Alternately you could choose to hide the entire forums, topics and all replies with ‘BBpress private setting’ but this will encourage other visitors to think that the support forums or community is not active and that’s bad for business 🙂

With this step, you can show all not logged in visitors the topics or questions created by your members but they(the not logged in) cannot view the answers or replies unless they logged in or become member to your site.

Related Topics:

WordPress Tutorials
Building Your Website with WordPress? Learn How to Optimize it
WordPress Tutorials
How to Detect Mobile or Tablet Condition in WordPress
WordPress Tutorials
Designing and Protecting Your WordPress Site is Easier Than You Think
WordPress Tutorials
The Ultimate SEO Tips For Your WordPress Blog
BBPress: How to hide replies from not logged in usershttp://cdn.dezzain.com/1/2014/10/hide-bbpress-forums-replies.jpghttp://cdn.dezzain.com/1/2014/10/hide-bbpress-forums-replies-150x150.jpgRichie KS WordPress TutorialsBBPress,WordPress TipsLearn how to hide your BBPress forums topic's replies from not logged in users. a simple add to functions.php code could save you from viewing theft or not logged in users abuse. DEZZAIN.COM
Enjoy This Article?, Follow us or Share it smiley
viral and buzz WordPress theme

4 Comments Already

  1. Wow… been searching for it like since day. I’m stunned to find such a short code. Tried everything! Love <3

    Public CommentUserWow... been searching for it like since day. I'm stunned to find such a short code. Tried everything! Love <3
  2. Thank you for the solution. it’s great.

    Public CommentUserThank you for the solution. it's great.
  3. Just want to ask the same as Mirela above.
    Would be great to have a modified code just to show a template-notice.
    “You have to login to view the answers”…
    Thanks
    Matthias

    Public CommentUserJust want to ask the same as Mirela above. Would be great to have a modified code just to show a template-notice. "You have to login to view the answers"... Thanks Matthias
  4. Thanks for this solution! It does do the trick. But can’t we make it not to show at ALL any replies? Even if it has the message “Log in to view replies” on it. I mean to have the topic and nothing else below, except the notifying message to login to view more..

    Regards!

    Public CommentUserThanks for this solution! It does do the trick. But can't we make it not to show at ALL any replies? Even if it has the message "Log in to view replies" on it. I mean to have the topic and nothing else below, except the notifying message to login to view more.. Regards!

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


You can wrap php, js or style css code with [PHP]..your code...[/PHP]