WordPress multisite password reset fix

to fix the issue with the wrong URLs

http://www.site2.com forgot password links to

http://www.site1.com/wp-login.php?action=lostpassword
and not
http://www.site2.com/wp-login.php?action=lostpassword

the fix is:

you change on the most lines network_site_url -> site_url
wp-includes/general-template.php

function wp_lostpassword_url( $redirect = '' ) {
	        $args = array( 'action' => 'lostpassword' );
	        if ( !empty($redirect) ) {
	                $args['redirect_to'] = $redirect;
	        }

	        $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
	        return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
}

should be

function wp_lostpassword_url( $redirect = '' ) {
	        $args = array( 'action' => 'lostpassword' );
	        if ( !empty($redirect) ) {
	                $args['redirect_to'] = $redirect;
	        }

	        $lostpassword_url = add_query_arg( $args, site_url('wp-login.php', 'login') );
	        return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
}

Also WordPress is generating the incorrect email in wp-login.php

$message = __('Someone requested that the password be reset for the following account:') . "rnrn";
	$message .= network_home_url( '/' ) . "rnrn";
	$message .= sprintf(__('Username: %s'), $user_login) . "rnrn";
	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "rnrn";
	$message .= __('To reset your password, visit the following address:') . "rnrn";
	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">rn";

should be

$message = __('Someone requested that the password be reset for the following account:') . "rnrn";
	$message .= home_url( '/' ) . "rnrn";
	$message .= sprintf(__('Username: %s'), $user_login) . "rnrn";
	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "rnrn";
	$message .= __('To reset your password, visit the following address:') . "rnrn";
	$message .= '<' . site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_

 

<form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">

should be

<form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">

 

$login_header_url   = network_home_url();

should be

$login_header_url   = home_url();

 

wp_die( __('The e-mail could not be sent.') . "<br />n" . __('Possible reason: your host may have disabled the mail() function.') );

should be

wp_die( __('The e-mail could not be sent.') . "<br />n" . __('Possible reason: your host may have disabled the mail() function, or enable the Plugin WP-Mail-SMTP and configure it.') );

 

$blogname = ['current_site']->site_name;

should be

$blogname = home_url( '/' );