Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwr456/404f1bfc8305b26e74d6b5554c4fe678 to your computer and use it in GitHub Desktop.
Save jwr456/404f1bfc8305b26e74d6b5554c4fe678 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 and Site Name in email that goes out.
// hardcoded to replace the default network site name of 'My Blog' because I don't know howto retrieve it dynamically
add_filter("retrieve_password_message", function ($message, $key) {
return str_replace('My Blog', get_option('blogname'), 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";
});
@jwr456
Copy link
Author

jwr456 commented Mar 26, 2021

this fork also replaces the Site Name in the body of the email

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