Forked from eteubert/wordpress-passwort-reset-unmultisite.php
Last active
July 10, 2024 22:52
-
-
Save VR51/33d32082a009de0a2c990e994aea8936 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: Do Password Reset on Local Blog instead of Root Blog | |
* Plugin URI (orig): https://gist.github.com/eteubert/293e07a49f56f300ddbb | |
* Plugin URI (this forke): https://gist.github.com/VR51/33d32082a009de0a2c990e994aea8936/ | |
* 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. | |
* Instructions: Drop into /wp-content/mu-plugins/ or remove this header and add to functions.php. Use mu-plugins if you want to affect all sites. | |
* Version: 1.0.1 | |
* Author: Eric Teubert + vr51 + others | |
* Author URI: http://ericteubert.de | |
* License: MIT | |
*/ | |
/** | |
* Password reset on sub site (1 of 4) | |
* Replace login page "Lost Password?" urls. | |
* | |
* @param string $lostpassword_url The URL for retrieving a lost password. | |
* @param string $redirect The path to redirect to. | |
* | |
* @return string | |
* | |
* @since 1.0.0 | |
*/ | |
function custom_lostpassword_url( $lostpassword_url, $redirect ) { | |
$use_url = false; | |
$args = array( 'action' => 'lostpassword' ); | |
// $args["wpe-login"] = "true"; // Uncomment if on WP Engine hosting | |
if ( ! empty( $redirect ) ) { | |
$args['redirect_to'] = $redirect; | |
} | |
if ( $use_url ) { | |
return esc_url( add_query_arg( $args, $lostpassword_url ) ); | |
} | |
return esc_url( add_query_arg( $args, site_url( 'wp-login.php' ) ) ); | |
} | |
add_filter( 'lostpassword_url', 'custom_lostpassword_url', 10, 2 ); | |
/** | |
* Password reset on sub site (2 of 4) | |
* Replace other "unknown" password reset urls. | |
* | |
* @param string $url The complete network site URL including scheme and path. | |
* | |
* @return string | |
* | |
* @since 1.0.0 | |
*/ | |
function replace_lostpassword_urls( $url ) { | |
if ( stripos( $url, 'action=lostpassword' ) !== false ) { | |
return site_url( 'wp-login.php?action=lostpassword' ); | |
} | |
if ( stripos( $url, 'action=resetpass' ) !== false ) { | |
return site_url( 'wp-login.php?action=resetpass' ); | |
} | |
return $url; | |
} | |
add_filter( 'network_site_url', 'replace_lostpassword_urls', 10, 3 ); | |
/** | |
* Password reset on sub site (3 of 4) | |
* Fixes the URLs in emails that are sent. | |
* | |
* @param string $message Default mail message. | |
* | |
* @return string | |
* | |
* @since 1.0.0 | |
*/ | |
function retrieve_password_message_urls( $message ) { | |
return str_replace(network_site_url(), get_site_url().'/', $message); | |
// return str_replace(get_site_url(1), get_site_url(), $message); // Uncomment this line and comment out the above line if blog site detection fails. | |
} | |
add_filter( 'retrieve_password_message', 'retrieve_password_message_urls' ); | |
/** | |
* Password reset on sub site (4 of 4) | |
* Fixes the title in emails that are sent. | |
* | |
* @return string | |
* | |
* @since 1.0.0 | |
*/ | |
function custom_retrieve_password_title() { | |
return sprintf( __( '[%s] Password Reset' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ); | |
} | |
add_filter( 'retrieve_password_title', 'custom_retrieve_password_title' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment