Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KZeni/7760876c01ebb681ad439a452dc64427 to your computer and use it in GitHub Desktop.
Save KZeni/7760876c01ebb681ad439a452dc64427 to your computer and use it in GitHub Desktop.
Multisite: Password Reset on Local Blog
<?php
/**
* Plugin Name: Multisite: Password Reset on Local Blog
* Plugin URI: https://gist.github.com/KZeni/7760876c01ebb681ad439a452dc64427
* Description: By default, WordPress Multisite uses the main blog for password resets. This plugin enables users to stay in their blog during the whole reset process.
* Version: 1.1.1
* Author: Eric Teubert + KZeni
* Author URI: https://gist.github.com/KZeni/7760876c01ebb681ad439a452dc64427
* License: MIT
*/
// fixes "Lost Password?" URLs on login page
add_filter(
"lostpassword_url",
function ($url, $redirect) {
$args = ["action" => "lostpassword"];
$args["wpe-login"] = "true"; // Comment out if not on WP Engine hosting; leave as-is (enabled) if on WPE hosting.
if (!empty($redirect)) {
$args["redirect_to"] = $redirect;
}
return add_query_arg($args, site_url("wp-login.php"));
},
12,
2
);
// fixes other password reset related urls
add_filter(
"network_site_url",
function ($url, $path, $scheme) {
if (stripos($url, "action=lostpassword") !== false) {
return site_url("wp-login.php?action=lostpassword", $scheme);
}
if (stripos($url, "action=resetpass") !== false) {
return site_url("wp-login.php?action=resetpass", $scheme);
}
return $url;
},
12,
3
);
// fixes URLs in email that goes out.
add_filter(
"retrieve_password_message",
function ($message, $key) {
//return str_replace(get_site_url(1), get_site_url(), $message);
return str_replace(
get_site_url(get_network()->site_id),
get_site_url(),
$message
);
},
12,
2
);
// fixes email title
add_filter("retrieve_password_title", function ($title) {
return "[" .
wp_specialchars_decode(get_option("blogname"), ENT_QUOTES) .
"] Password Reset";
});
@KZeni
Copy link
Author

KZeni commented May 3, 2024

@geodefender Oh, and I did do some quick Googling just in case you do host with WP Engine... https://wordpress.org/support/topic/lost-password-link-not-working-7/#post-17070821 shows someone else using WPS Hide Login on WP Engine (while multi-site network wasn't mentioned) where they needed WP Engine support to make a caching exception to get the reset password working properly for them. I'd imagine that would be just as applicable for a multisite network setup just as much as a single site setup (again, just making suggestions for things to possibly try/look into since I'm not using that same plugin as you.)

Also, it's recommended to clear your WP Engine caches fully & reset file permissions (the latter being less likely to be needed, but should be a harmless precaution) via WP Engine's tools after you added & enabled this code as it is possible that you were given a result where some part of it was cached from how it was behaving before while it might be all good if/when the cache refreshes.

@geodefender
Copy link

Hi @KZeni, thank you so much for your quick support.
I don't use WP Engine, I use Linode.
Sorry I'm not a coder, do you have any suggestion? The original code doen't work also for me.

@KZeni
Copy link
Author

KZeni commented May 6, 2024

@geodefender Ah, yeah, this was me adapting existing code (https://gist.github.com/eteubert/293e07a49f56f300ddbb) to work with Paid Membership Pro on WP Engine so you should certainly be looking elsewhere since you're using WPS Hide Login (instead of PMP) and Linode (instead of WPE) where my adapted code is less likely to work compared to the code I started with (see eteubert's gist) since I just made 2 changes to accommodate 2 things you're not using.

You might just need to contact WPS Hide Login's support (at least via their WP.org support forum) to report the issue you're having (mentioning you're on Linode as a side detail so it rules out other hosting-specific possibilities) so they can help you fix/adapt the behavior of their plugin to meet your needs (I'm sure you're not the first one to encounter this with WPS Hide Login.)

You might also have luck asking the eteubert gist's comments as there might be a fork of that starter code that's then unique to your setup (similar to how I started with that and made this forked version for PMP & WPE per my needs.)

Best of luck. I can't really devote more time as that's using a setup that's completely different from mine so I'm not involved other than lending a hand & making suggestions as an outsider who isn't encountering the issue you're having (per my setup using a different plugin & hosting provider while then not being associated with any of these plugins/etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment