Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • @porcusheep

    Participant

    I got it working! Thank you so much for you help Henry.
    I ended up modifying the code I found in this post: https://buddypress.org/support/topic/hiding-groups-activity-members-list-to-non-members/

    Ran into some issues as bp_is_page( BP_MEMBERS_SLUG ) is no longer working, replaced it with your bp_is_members_directory()

    Then had to figure out why bp_is_page() doesn’t work, found it is replaced with is_page()

    After, some figuring out how to use is_page(), I got everything working with the code below:

    function nonreg_visitor_redirect() {
    	global $bp;
    
    	if (is_page('alchemist-top-250-companies') ) {
    	
    		if(!is_user_logged_in()) {
    			wp_redirect('/stillneedtosetupage' );
    		}
    		
    	}
    	
    	if (bp_is_members_directory() ) {
    	
    		if(!is_user_logged_in()) {
    			wp_redirect('/register' );
    		}
    	}
    }
    add_filter('get_header','nonreg_visitor_redirect',1);

    @porcusheep

    Participant

    I am trying to make it so
    https://www.example.com/example/
    is viewable to logged in members only. If you aren’t logged in, I want people to be redirected to https://www.example.com/example2/

    Also, I just added the code below and I can still access the members directory when not logged in.:

    add_action( 'init', function() {
        if ( ! is_user_logged_in() && bp_is_members_directory() ) {
            bp_core_redirect( site_url().'/register' );
        } else {
            // Do nothing.
        }
    } );

    If I change the code to the one below, I get an endless redirect loop error when trying to load any page of my site regardless if I’m logged in or not…:

    add_action( 'init', function() {
        if ( ! is_user_logged_in() && site_url().'/members'  ) {
            bp_core_redirect( site_url().'/register' );
        } else {
            // Do nothing.
        }
    } );

    @porcusheep

    Participant

    Are you logged in?

    That link is to the home directory of your forums. You would need to select a section like general discussion to start a new thread. like here: http://freelanceppl.com/forum/?view=forum&id=2

    From there, if you are logged in, there should be a button labeled “+ New Topic”

    *Note* I registered a test account to look into this for you. Feel free to delete the account name “testtest”

    @porcusheep

    Participant

    Thanks Henry!
    That looks like it would work for my members directory but what about doing this for a conditional redirect for a specific post page? What I’m looking for is if they go to a specific post page and they are not logged in, they get to see a different page than if they were logged in.

    Would I do something like this?:

    add_action( 'init', function() {
        if ( ! is_user_logged_in() && get_option(‘siteurl’) . ‘/Page A URL here’  ) {
            bp_core_redirect( "Page B url here" );
        } else {
            //do nothing
        }
    } );

    Also, where do I put this code?

Viewing 4 replies - 1 through 4 (of 4 total)
Skip to toolbar