Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to configure forums using the bbpress plugin that can only be viewed by logged in users. I attempted creating them as private but found that sub-forums don't show up on my root /forums page. Another forum suggested using is_user_logged_in() to determine whether or not forums are displayed.

What is the best place to put a check for is_user_logged_in() that will hide all forum related pages and posts from non-logged in users. I am up for other suggestions as well if there is a better way to do it, but I am not finding much documentation.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The solution I went with was to create a file in my theme's folder named bbpress.php. I then copied the contents of my theme's page.php file into the new file and modified it to only show it's contents when a user is logged in. In my case it looked like the following:

if( is_user_logged_in() ) {
    get_template_part( 'loop', 'page' );
}
else{
    _e('You must be logged in to view this page.', 'twentyten-child');
}

Apparently the bbpress plugin looks in a a particular order for the template it will use (see http://bbpress.org/forums/topic/where-do-i-choose-a-custom-template-for-the-bbpress-20-plugin). I chose to name the file bbpress.php since it makes it clear when I look back at my code what the file is connected to.

share|improve this answer
    
Please mark your answer (this one) as correct. This will stop people from coming here thinking that the problem isn't solved. Thanks! –  BandonRandon Dec 8 '12 at 8:06
    
Just updating this solution with a new link for what order BBPress looks for templates: bbpress.org/forums/topic/… –  RachieVee Feb 5 at 3:58

The only way I've gotten around this so far is using version 2.1 from the trac site and setting things up so the top-level forums are categories instead of forums, ie:

  • Top Public (category)
    • Sub public forum
    • Sub public forum
  • Top Members (category)
    • Sub members forum
    • Sub members forum

Set the members forums and top level category to "hidden", and use the Members plugin to allow whatever other user levels besides admin permission to view hidden forums.

Any other variation I've tried gives the same results you indicated, and this fix doesn't seem to work in 2.0 due to a bug in setting the visibility on forums. Requires some further testing once 2.1 is officially released, but it's working for me so far.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.