Last active
October 6, 2024 19:59
-
-
Save eteubert/293e07a49f56f300ddbb to your computer and use it in GitHub Desktop.
Multisite: Passwort Reset on Local Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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 be12
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 appendwpe-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 than12
(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 of12
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.