zm-ajax-login-register
zm-ajax-login-register copied to clipboard
Default redirection is not working properly on multisite and search result pages
The bug #95 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 (in plugin.php inside function zm_ajax_login_register_localized_js()
):
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.
Reading the code i guess it is not working properly, even if you set a redirection.
Thanks for pointing this out. Honestly I had always used network_site_url
, as it will fall back on [site_url](https://codex.wordpress.org/Function_Reference/site_url)
if it is not a multisite.
The only issue with [home_url](https://codex.wordpress.org/Function_Reference/home_url)
is that it does not support multisite.
I'll look deeper into this. Could you submit a pull request?
I see what you say about home_url, also site_url, but i think it is related to determine the url of the WP installation when you need to use network_site_url(). I have to clone the repository in order to do the pull request. I'll research a little bit too about to send you a better code.
I believe the right way to do it is using site_url or home_url instead of network_site_url, anyway i see no issues when using home_url or site_url and it was the recommendation i got for another code when redirecting to the current page.
I just did the pull request.