Created
June 29, 2015 17:01
-
-
Save alloyking/2a8f0393b54748a52a8c to your computer and use it in GitHub Desktop.
WP multisite lost password redirection
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
add_action('lostpassword_post', 'validate_reset', 99, 3); | |
function validate_reset(){ | |
if(isset($_POST['user_login']) && !empty($_POST['user_login'])){ | |
$email_address = $_POST['user_login']; | |
//is this an email reset? | |
if(filter_var( $email_address, FILTER_VALIDATE_EMAIL )){ | |
if(!email_exists( $email_address )){ | |
wp_redirect( $_POST['redirect_to'].'/register' ); | |
exit; | |
} else { | |
wp_redirect( $_POST['redirect_to'].'/register' ); | |
} | |
}else{ | |
// if a username reset | |
$username = $_POST['user_login']; | |
if ( !username_exists( $username ) ){ | |
wp_redirect( $_POST['redirect_to'].'/register' ); | |
exit; | |
} else { | |
wp_redirect( $_POST['redirect_to'] ); | |
exit; | |
} | |
} | |
}else{ | |
//user submitted nothing... | |
wp_redirect( $_POST['redirect_to'].'/register' ); | |
exit; | |
} | |
} | |
add_filter( 'lostpassword_url', 'my_lost_password_page', 10, 2 ); | |
function my_lost_password_page( $lostpassword_url, $redirect ) { | |
// /wp-login.php?action=lostpassword | |
return home_url( '/wp-login.php?action=lostpassword&redirect_to=' . home_url() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment