Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default redirection with WP Networking #95

Closed
zanematthew opened this issue Feb 10, 2015 · 3 comments
Closed

Default redirection with WP Networking #95

zanematthew opened this issue Feb 10, 2015 · 3 comments
Labels
Milestone

Comments

@zanematthew
Copy link
Owner

There's a small bug reported via the .org forum: https://wordpress.org/support/topic/little-bug-on-default-redirection

@arthurmolina
Copy link

:) +1

@zanematthew zanematthew added this to the 1.0.9 milestone Mar 17, 2015
zanematthew pushed a commit that referenced this issue May 7, 2015
@zanematthew
Copy link
Owner Author

The redirect url is now handling like this:

// Get the option from the db
$redirect_url = get_option('ajax_login_register_redirect');

// If its empty just use the current page
if ( empty( $redirect_url ) ){
    global $wp;
    $formatted_url = trailingslashit( add_query_arg( '', '', network_site_url( $wp->request ) ) );
}

// If it is just a slug, i.e., foo/a/b/c lets use the network site url, which falls back on site url, and append it
// network site url also handles setting the protocol, i.e., http/https
elseif ( strpos( $redirect_url, 'http' ) === false ) {
    $formatted_url = network_site_url( $redirect_url );
}

// Just use what ever they entered, of course escape url it
else {

    $formatted_url = esc_url( $redirect_url );
}

// last allow for it to be filtered.
$redirect_url = apply_filters( 'zm_ajax_login_redirect', $formatted_url );

@cablop
Copy link

cablop commented Jun 23, 2015

This bug is not solved. It is working bad on WPMU (aka WP Network) installs, because it is redirecting to the main site, not working on subsites. Also, it is not working for search result pages and alike. I think the problem is you are both using the wrong function to get the site URL part and you are not considering the query. I had to modify the code this way:

    if ( empty( $redirect_url ) ){
        global $wp;
//      $formatted_url = trailingslashit( add_query_arg( '', '', network_site_url( $wp->request ) ) );
        if ($wp->query_string) {
            $formatted_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
        }
        else {
            $formatted_url = trailingslashit( add_query_arg( '', '', home_url( $wp->request ) ) );
        }
    }

    // This is just a slug, and doesn't have http(s), so lets add it
    elseif ( strpos( $redirect_url, 'http' ) === false ) {
//      $formatted_url = network_site_url( $redirect_url );
        $formatted_url = home_url( $redirect_url );
    }

Using home_url instead of network_site_url, and using $wp->query_string as an argument of add_query_arg. That way i can return even to search result pages and other custom URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants