Support » Themes and Templates » Blocking bbPress forums unless logged in

  • pealo86

    (@pealo86)


    I’m using a bit of code to redirect the user to the login page if they try viewing my forums without being logged in:

    if (get_the_ID() == 84) {
    	if (!is_user_logged_in()) {
    		header('Location: ' . get_permalink(102));
    	}
    }

    However, I’ve realised this doesn’t protect the pages inside the forums, such as individual threads and the forum rooms.

    Does anyone know of a way to password protect the whole forum section?

Viewing 4 replies - 1 through 4 (of 4 total)
  • pealo86

    (@pealo86)

    In case anyone is wondering, I managed to block the whole forums section like so:

    // forward to login if page is protected
    // forums
    if (get_post_type() == 'forum') {
    	if (!is_user_logged_in()) {
    		header('Location: ' . get_permalink(102));
    	}
    }
    pealo86

    (@pealo86)

    Or more like:

    // forward to login if page is protected
    // forums
    if (get_post_type() == 'forum' || get_post_type() == 'topic') {
    	if (!is_user_logged_in()) {
    		header('Location: ' . get_permalink(102));
    	}
    }

    maybe i should already know this, but what am i supposed to put after Location:?

    i’m putting this in my wordpress stylesheet, is that right? or is it better to put it into bbpress’s own file?

    It needs to go right at the top of your header.php file

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Blocking bbPress forums unless logged in’ is closed to new replies.