Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Updates URLs on susbites and in lost password request emails to point to the subsite where the lost password request started.
<?php
/*
Plugin Name: Subsite Lostpassword
Plugin URI: http://www.paidmembershipspro.com/wp/subsite-lostpassword/
Description: Updates URLs on susbites and in lost password request emails to point to the subsite where the lost password request started.
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
Fixes the URL at the bottom of the login page.
*/
function sslp_lostpassword_url($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 );
}
add_filter("lostpassword_url", "sslp_lostpassword_url", 10, 2);
/*
Fixes URL in email that goes out.
*/
function sslp_retrieve_password_message($message, $key)
{
if ( empty( $_POST['user_login'] ) ) {
return $message; //error probably
} else if ( strpos( $_POST['user_login'], '@' ) ) {
$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
if ( empty( $user_data ) )
return $message; //another error condition, no user found
} else {
$login = trim($_POST['user_login']);
$user_data = get_user_by('login', $login);
}
$user_login = $user_data->user_login;
$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
$message .= home_url( '/' ) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
$message .= '<' . site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
return $message;
}
add_filter("retrieve_password_message", "sslp_retrieve_password_message", 10, 2);
@shiyam06

This comment has been minimized.

Copy link

@shiyam06 shiyam06 commented Mar 12, 2014

I tried this plugin, but shows up 'Internal server Error" when Logging out for checking the link.

@tim-field

This comment has been minimized.

Copy link

@tim-field tim-field commented May 15, 2014

I'm seeing the same error as shiyam06 with

Premature end of script headers

in the error log.

@Shadowstep33

This comment has been minimized.

Copy link

@Shadowstep33 Shadowstep33 commented Aug 1, 2014

To fix this problem, replace like 20 and 21 with:

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

I would suggest replacing this in the code itself strangerstudios. It fixes the Internal Server Error (which throws a 520 Unknown Error if you have cloudflare on. Took me some time and good debugging skills to figured this one out).

@landshark22

This comment has been minimized.

Copy link

@landshark22 landshark22 commented Oct 28, 2014

This seems to not be working in the latest version of Wordpress (multisite)

@eteubert

This comment has been minimized.

Copy link

@eteubert eteubert commented Apr 15, 2015

I wrote my own implementation, if anyone still needs it: https://gist.github.com/eteubert/293e07a49f56f300ddbb

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