8

I have a multisite network. I want my users to be able to reset their passwords while staying within their subsites. So for example clicking the "lost your password?" link keeps them within their subdomain (subdomain.domain.com/wp-login.php?action=lostpassword) as opposed to taking them to the main site (domain.com/wp-login.php?action=lostpassword).

After they submit the username or email to reset the password, I would like for that email to contain links back to their subdomain and not the main site as is the default functionality.

Prior to the 4.0 update I was able to use this patch https://core.trac.wordpress.org/ticket/21352 and ultimately this plugin https://gist.github.com/strangerstudios/9487278 to get the exact functionality described above. All was great.

However after the update it is no longer working. Asking for assistance in the various places referenced has still not helped solve the problem. Is anyone able to help?

1
  • Updated to 4.1, still having the same problem.
    – Mike
    Jan 7, 2015 at 18:15

1 Answer 1

7

This works well!

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

<?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";
});
2
  • This works well thanks! I added the filters and actions into the functions.php file and it works just as well. Also into the network_site_url I added another condition for the newly added users email. if (stripos($url, "action=rp") !== false) return site_url( $path, $scheme );
    – Joe
    Sep 10, 2020 at 9:41
  • @Joe what do you mean by "newly added users email"? I did not need this line even when changing a user email address.
    – baptx
    Apr 7, 2021 at 19:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.