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