BuddyDev

Search

Redirect Loggedout Users to a 'Register Page'

  • Participant
    Level: Enlightened
    Posts: 89
    Graham Hoffman on #17127

    Hey Brajesh,

    Is there a way to redirect logged out users (BuddyPress) to a information/login page?
    For example: https://skirmishersdefence.co.uk/airsoftnation/home-register/

    Once they’re logged in, redirect to whatever page they were trying to view, or perhaps the homepage?

    -My concern is that I don’t want google to not be able to index the website – would it affect the crawl?
    -Can I make the blog open to read, but other specific pages ‘required registration’ ?

  • Participant
    Level: Enlightened
    Posts: 89
    Graham Hoffman on #17128

    I’ve just noticed WPMUDev do have a Login Redirect, so this should be sufficient.

    https://premium.wpmudev.org/project/login-redirect/

  • Participant
    Level: Enlightened
    Posts: 89
    Graham Hoffman on #17129

    Scrap that, it’s not compatible with BuddyPress haha.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17130

    Hi Graham,
    Welcome back.

    For logout, you can use the following code. Works with BuddyPress too

    
    /**
     * Redirect user on logout.
     *
     * @param string $logout_url logout url.
     * @param string $redirect where to redirect.
     *
     * @return string
     */
    function buddydev_custom_logout_url( $logout_url, $redirect ) {
    
    	$redirect            = bp_get_signup_page();
    	$args                = array( 'action' => 'logout' );
    	$args['redirect_to'] = $redirect;
    
    	$logout_url = add_query_arg( $args, site_url( 'wp-login.php', 'login' ) );
    	$logout_url = wp_nonce_url( $logout_url, 'log-out' );
    
    	return $logout_url;
    }
    
    add_filter( 'logout_url', 'buddydev_custom_logout_url', 100, 2 );
    
    

    Change ‘redirect_url’ to wherever you need to redirect.

    For redirecting on login to the visiting page, BuddyPress alreadyu does it. Also, Our BP Ajax Registration 2.0 is coming today/tomorrow and if you use it for login with page reload method, it can solve your issue.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved