BuddyDev

Search

[Resolved] Logout and redirect to Register

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #42070

    Hello Jimmy,

    Thank you for posting. Please try using the code from the following link:

    https://buddydev.com/support/forums/topic/redirect-loggedout-users-to-a-register-page/#post-17130

    Please let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 66
    Jimmy Cheung on #42078

    Hi Ravi,

    Yahoo and Way2Go! It works like a charm using this function. I now selected the dropdown and changed to the register page, It go straight to the register page after logged-out.

    OMG! Thank you so very much for helping me.

  • Participant
    Level: Enlightened
    Posts: 66
    Jimmy Cheung on #42081

    Hi Ravi,

    This is an update information

    My bad, I now realized, instead NOT going to the profile page after logged-in or even when I click the site logo, it goes to the members page instead NOT the profile page?

    Please help help,
    Thanks,

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #42083

    Hello Jimmy,

    Please remove all previous code and use the following code:

    
    
    /**
     * 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 ) {
    
    	if ( ! function_exists( 'buddypress' ) ) {
    		return $logout_url;
    	}
    
    	$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 );
    
    /**
     * Modify custom login redirect url
     *
     * @param string $login_url Login url.
     *
     * @return string
     */
    function buddydev_custom_login_url( $login_url ) {
    
    	if ( ! function_exists( 'buddypress' ) ) {
    		return $login_url;
    	}
    
    	$login_url = remove_query_arg( 'redirect_to', $login_url );
    
    	$new_redirect_url = trailingslashit( bp_get_members_directory_permalink() . 'me' );
    
    	$login_url = add_query_arg( 'redirect_to', $new_redirect_url, $login_url );
    
    	return $login_url;
    }
    
    add_filter( 'login_url', 'buddydev_custom_login_url' );
    
    

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 66
    Jimmy Cheung on #42094

    OMG YES Ravi,

    You hit it right on the nose 🙂 I even tested dozen of times. Works like a charm!!!

    Thank you so much for your big time help again and again!!!

    —————–

    P.S. Ravi, I’m still wondering, why sending logged-out members to the register page that they already have an account.

    What about a function to send ALL (ANY) visitors who landed on the homepage or any pages that was NOT LOGGIN to the REGISTER PAGE instead.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #42143

    Hello Jimmy,

    Thank you for the acknowledgment. I will check and will update you.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #42146

    Hello Jimmy,

    Please look at the following blog to make the site private.

    https://buddydev.com/making-a-wordpress-buddypress-site-private-the-right-way/

    Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 66
    Jimmy Cheung on #42160

    Hi Yogi,

    There must be a demon on my site LOL, I had tried dozen of different ways and keep staying on the homepage as visitor.

    Can you help me with the correct url to see what I’m doing wrong?

    The ONLY line I changed/add for this function is this below.

    $redirect_url = wp_login_url( site_url(‘/https://ThisIsMySite.com/register.php/’) );//get login url,

    Please help help,
    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #42167

    Hello Jimmy,

    Do you want to redirect visitors to the home page or login page? The current version of code redirects users to the login page.

    Regards
    Ravi

The topic ‘ [Resolved] Logout and redirect to Register’ is closed to new replies.

This topic is: resolved