Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp Private Group Non-Logged In User Redirect

  • @simonbegg

    Participant

    Hi,

    I’m having an issue setting up bbp Private Groups to work exactly as required.

    I’ve set up a private forum to be visible only to logged in users (I also have other forums visible to all).
    This works fine in that the forum is invisible to non-logged in users.
    However when a non-logged in user goes directly to the private forum url (eg http://teamtwobees.com/forum/facebook-advertising/) they are presented with a 404 page. I’d like these users to be redirected to a log in page and then redirected back to the private forum after having logged in.

    I’ve set the ‘URL of redirect page for NON-LOGGED-IN’ option but this doesn’t seem to have any affect – users still get the 404 page.

    What is the correct way to achieve what I’m looking for?

    bbPress v 2.5.6
    bbp Private Groups v 2.5.6
    WordPress v 4.1.1

    Thanks

    Simon

Viewing 16 replies - 1 through 16 (of 16 total)
  • @robin-w

    Moderator

    check that you have put the url in correctly – copy from the setting into your browser and check that it works it needs to be the full url

    @simonbegg

    Participant

    The URL is definitely correct.
    Is what I’m trying to achieve standard functionality?

    @robin-w

    Moderator

    Can you post here what you have put into the setting?

    @simonbegg

    Participant

    Just trying to redirect to the login page, have tried other URL’s as well.
    http://teamtwobees.com/wp-login.php

    Click to activate forum visibility is ticked.
    Forum visibility is set to ‘Private’

    Thanks
    Simon

    @robin-w

    Moderator

    yes for a private forum with visibility that is the expected behaviour.

    If the forum is private then it is not seen by non-logged in users, so the logic is that as you don’t expect non-logged in users to know that the forum exists, you wouldn’t want them to know that a topic exists, and login would tell them that they url existed, so they get a 404 in all cases.

    Set the forum to public, and the logon screen will appear.

    @simonbegg

    Participant

    Ok, makes sense. Think I’ve got the hang of it now.
    Thanks for your help,

    Simon

    @robin-w

    Moderator

    Great – glad you’re fixed !

    @paaljoachim

    Participant

    I added a link to a private forum in the menu so that a logged in user could easily access the forum. Yes I could add a menu for logged in users, but I decided to instead redirect the not logged in users.

    Here is the code I used:

    // Redirect private bbPress forum to specific page.
    add_action('template_redirect', 'private_content_redirect_to_login', 9);
    function private_content_redirect_to_login() {
      global $wp_query,$wpdb;
      if (is_404()) {
        $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        $path = dirname($_SERVER['REQUEST_URI']);
        $forums = "forum";
        $location = "https://direitoshumanosangola.org/not-logged-in/";
        }
        if(strpos( $path, $forums ) !== false){
          wp_safe_redirect($location);
          exit;
      }
    }

    I made a tutorial for it here:
    https://www.easywebdesigntutorials.com/hide-buddypress-pages-and-bbpress-forums-from-not-logged-in-users/

    @robin-w

    Moderator

    that’s great – thanks for posting your solution and a tutorial – that will definitely help others 🙂

    @meilleurgrossiste

    Participant

    hello,
    Thanks for the tutorial

    @ruthvant2022

    Participant

    Hi this function no longer works in PHP8.1, can you do an update?

    It’s complaining about these two lines

    if(strpos( $path, $forums ) !== false){
    wp_safe_redirect($location);

    @robin-w

    Moderator

    what is the exact error?

    @ruthvant2022

    Participant

    Hi
    Warning: Undefined variable $path in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 362

    Warning: Undefined variable $forums in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 362

    Warning: Undefined variable $location in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 363

    It stops anything else loading the page is just blank other than this message. If I remove the function everything works.

    @robin-w

    Moderator

    php 8.1 is a lot more fussy

    try this (untested but should work)

    function private_content_redirect_to_login() {
      global $wp_query,$wpdb;
      if (is_404()) {
        $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        $path = dirname($_SERVER['REQUEST_URI']);
        $forums = "forum";
        $location = "https://direitoshumanosangola.org/not-logged-in/";
    		if(strpos( $path, $forums ) !== false){
    		  wp_safe_redirect($location);
    		  exit;
    		}
      }
    }

    @ruthvant2022

    Participant

    Spot on, thank you.

    @robin-w

    Moderator

    no problem – glad you are fixed 🙂

Viewing 16 replies - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.
Skip to toolbar