Skip to content

Instantly share code, notes, and snippets.

@eteubert
Last active April 15, 2024 20:45
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save eteubert/293e07a49f56f300ddbb to your computer and use it in GitHub Desktop.
Save eteubert/293e07a49f56f300ddbb to your computer and use it in GitHub Desktop.
Multisite: Passwort Reset on Local Blog
<?php
/**
* Plugin Name: Multisite: Passwort Reset on Local Blog
* Plugin URI: https://gist.github.com/eteubert/293e07a49f56f300ddbb
* Description: By default, WordPress Multisite uses the main blog for passwort resets. This plugin enables users to stay in their blog during the whole reset process.
* Version: 1.0.0
* Author: Eric Teubert
* Author URI: http://ericteubert.de
* License: MIT
*/
// fixes "Lost Password?" URLs on login page
add_filter("lostpassword_url", function ($url, $redirect) {
$args = array( 'action' => 'lostpassword' );
if ( !empty($redirect) )
$args['redirect_to'] = $redirect;
return add_query_arg( $args, site_url('wp-login.php') );
}, 10, 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;
}, 10, 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);
}, 10, 2);
// fixes email title
add_filter("retrieve_password_title", function($title) {
return "[" . wp_specialchars_decode(get_option('blogname'), ENT_QUOTES) . "] Password Reset";
});
@Av10ex
Copy link

Av10ex commented Jan 7, 2023

This plugin really saved my day. However for me it only works with Wordpress Default Login. I am using Paid Memberships Pro and would like to use PmPro login page (in my case named /login). There must be an easy way to tweak the plugin so that wp-login.php is replaced by /login/ in the lostpassword email? That would solve my issue. Secondly - this plugin seems not to work if Maintenance plugin is active.

@ANOVATIS
Copy link

ANOVATIS commented Mar 1, 2024

@Av10ex - does it not work if you replace all the wp-login.php by login?

@KZeni
Copy link

KZeni commented Apr 15, 2024

@Av10ex Not sure if you're still wanting/needing this yet or not... but I think I found a resolution via my forked version of this code at https://gist.github.com/KZeni/7760876c01ebb681ad439a452dc64427.

In effect, I just bumped the priority of the filters from 10 to instead be 12 as it appears (and maybe this is only when the Paid Memberships Pro [PMP] site is also on WPEngine hosting as is it in my case [since PMP then does its own URL adjustments to append wpe-login=1 to the assorted URLs to help with WPE hosting compatibility; which it seems my forked version works without it while on WP Engine [without needing to detect WPE within this gist to then selectively include it... one could also just hard-code the addition of that argument into the gist's $args if one knows the site will be on WPEngine for the foreseeable future] then just honoring the current site URL being viewed in the multi-site/network]) that this needs to happen after any number of adjustments being made to these URLs with a stronger priority than 12 (preventing them from being overwritten by reducing the number of filter[s] that might be remaining & come after this in priority.) Now, maybe the priority of 12 doesn't work for you, but this one change did seem to do the trick for my setup.

I also renamed "passwort" to "password" in a few spots (including the file name), made the URL that's sent out grab what it sees as the current site rather than still sending it as get_site_url(1) per line 37 of this original gist (as it is now; I just commented out the old line and added the new one below it on my fork), pointed it to my forked Gist for the URLs, and ran Prettier on the code.

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