Setting 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
[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’ );[/php]
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.