WordPress.org

Ready to get started?Download WordPress

Forums

Blocking bbPress forums unless logged in (5 posts)

  1. pealo86
    Member
    Posted 2 years ago #

    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?

  2. pealo86
    Member
    Posted 2 years ago #

    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));
    	}
    }
  3. pealo86
    Member
    Posted 2 years ago #

    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));
    	}
    }
  4. dangwhatno
    Member
    Posted 1 year ago #

    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?

  5. pealo86
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic