Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress and redirect_to

  • @ricks033

    Participant

    I have two websites running custom php to create Log In/Log Out entries on the menu.

    The Log Out behavior is different on the two websites. I finally tracked down the problem to bbPress. The URL created by my custom code with w_logout_url() on the bbPress site includes:
    &redirect_to=…

    where the URL created by the site without bbPress installed does not.

    Disabling bbPpress removes the &redirect_to=… and reenabling bbPress makes the redirect_to return.

    That leads me to believe bbPress is changing /setting this value somewhere, but I don’t see any choice to change that value in the bbPress settings?

    add_filter( 'wp_nav_menu_items', 'ccc_add_loginout_link', 10, 2 );
    function ccc_add_loginout_link( $items, $args ) {
        if (is_user_logged_in() && $args->theme_location == 'header-menu') {
            $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'header-menu') {
            $items .= '<li><a href="'. site_url('wpflogin') .'">Log In</a></li>';
        }
        return $items;
    }

    Thanks!!

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

    Moderator

    I did a code search and found this function in includes/common/functions line 1507 which seems a highly likely candidate.

    function bbp_logout_url( $url = '', $redirect_to = '' ) {
    
    	// If there is no redirect in the URL, let's add one...
    	if ( ! strstr( $url, 'redirect_to' ) ) {
    
    		// Get the forum root, to maybe use as a default
    		$forum_root = bbp_get_root_url();
    
    		// No redirect passed, so check referer and fallback to request uri
    		if ( empty( $redirect_to ) ) {
    
    			// Check for a valid referer
    			$redirect_to = wp_get_referer();
    
    			// Fallback to request uri if invalid referer
    			if ( false === $redirect_to ) {
    				$redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    			}
    		}
    
    		// Filter the $redirect_to destination
    		$filtered  = apply_filters( 'bbp_logout_url_redirect_to', $redirect_to );
    
    		// Validate $redirect_to, default to root
    		$validated = wp_validate_redirect( $filtered, $forum_root );
    
    		// Assemble $redirect_to and add it (encoded) to full $url
    		$appended  = add_query_arg( array( 'loggedout'   => 'true'   ), $validated );
    		$encoded   = urlencode( $appended );
    		$url       = add_query_arg( array( 'redirect_to' => $encoded ), $url       );
    	}
    
    	// Filter & return
    	return apply_filters( 'bbp_logout_url', $url, $redirect_to );
    }

    so maybe filtering on ‘bbp_logout_url’ would work.

    Let me know if you need further help

    @ricks033

    Participant

    Thank you. I don’t know why bbForum decides that if the logout isn’t being redirected, that bbForum must take over the redirect. Esp. without an option to turn it off.

    But at least now I know.

    @robin-w

    Moderator

    you can filter that to stop it

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