niiiice. you could also check out s2Member plugin, but this is just plain slick.
i’m sure we’ll be seeing an update soon that will asplode everything we’ve done so far, but until then, very cool workaround.
WR!
My final solution was to make bbPress ‘dumb’ when it comes to logged out users. I.e., it could either be clever and say “there are topics, but you’re not allowed to see them until you login” or it could just say “there are no topics”.
Thanks for the code! I have it working but I dont follow what you mean with the quoted login.
Is this a shortcode setting, or are you changing the default message of “Oh bother! No forums were found here!”.
I’m not changing the message at all – hence the “dumb” behaviour.
I see. You were suggesting that we change the message to something else.
Thanks for this code. Ive been waiting for something like this, and was about to start working on a plugin to do the same thing.
I’ve looked into a plugin called Role Scoper which grants you the ability to restrict things based on WordPress user roles and capabilities. Admittedly, the plugin is a bit bulky for what’s being accomplished with the above code but it’s an option.
I blogged about this little tweak too and someone has just posted an edit to display a friendly message instead of the standard “not found” which sort of completes it 
http://philipjohn.co.uk/2011/11/14/hiding-bbpress-topics-from-logged-out-users/#comment-1885
Found Phillips’ brilliant code awhile back. I changed it a little bit for more control:
function lab_logged_in_bbptopics($have_posts){
if (!bbp_current_user_can_publish_forums()){
$have_posts = null;
}
return $have_posts;
}
add_filter(‘bbp_has_topics’, ‘lab_logged_in_bbptopics’);
add_filter(‘bbp_has_forums’, ‘lab_logged_in_bbptopics’);
add_filter(‘bbp_has_replies’, ‘lab_logged_in_bbptopics’);
You can then use any of the user role plugins to specify which user (or user level) can publish forums. Of course, logged out users don’t have a bbp_current_user_can_publish_forums() set so they’ll automatically be denied access to the forums. Hope you enjoy!
Also, I changed the “Oh bother! …” text in bbpress/feedback-no-forums.php to say “You have to be logged in and have permission to see the forums.”
Hope this helps someone. And, thank you Philip for sharing your code to begin with! It certainly helped me a lot.
Hi, I’m very late to this thread.
But is there some plugin which could show “You need to login to view this page” instead of “Page cannot be found”?
Hi,
@philipjohn
Try this code in your function file, it shows only the titles (of topics) but no the content.
//Restrict Topic and Replies Content For No-Registered Users
function pj_hla_logged_in_topics($have_posts){
if (!is_user_logged_in()){
$have_posts = null;
}
return $have_posts;
}
add_filter('bbp_has_replies', 'pj_hla_logged_in_topics');
Regards,
@philipjohn
I blogged about this little tweak too and someone has just posted an edit to display a friendly message instead of the standard “not found” which sort of completes it 🙂
http://philipjohn.co.uk/2011/11/14/hiding-bbpress-topics-from-logged-out-users/#comment-1885
This above link is not working, can you pls share the correct link to that post of yours?
There is a plugin that does private groups – hiding anything and everything as needed, with controls on who can see and who can post and when.
Private groups
@zopfan – this code may be useful
//redirect user to log in page if accessing forum from external link
add_action( 'template_redirect', 'forum_redirect_from_external_link' );
function forum_redirect_from_external_link() {
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$actual_link = explode('/',$actual_link);
if($actual_link[3]=="forums" && !is_user_logged_in() ) {
wp_redirect( home_url('your-forum-log-in-page-here') );
exit;
}
}