zanematthew / zm-ajax-login-register

Creates a simple login and register modal with an optional shortocde

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default redirection with WP Networking

zanematthew opened this issue · comments

:) +1

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 );

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.