Last active
February 26, 2018 05:13
-
-
Save bhays/9c47731d530f9a232d37ddf67cf0c83e to your computer and use it in GitHub Desktop.
Allow email only for WordPress password reset requests
This file contains hidden or 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
// Return error if email is not set for password retrieval | |
add_action( 'lostpassword_post', 'email_only_lostpassword_post', 10, 1 ); | |
function email_only_lostpassword_post( $errors ){ | |
if( !is_email($_POST['user_login']) ){ | |
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid email addreess.')); | |
return $errors; | |
} | |
} | |
// Translate some login page text | |
add_filter( 'gettext', 'email_only_login_labels', 20, 3 ); | |
function email_only_login_labels( $translated_text, $text, $domain ) { | |
if (in_array( $GLOBALS['pagenow'], array( 'wp-login.php' ) )) { | |
if ($translated_text === 'Username or Email Address') { | |
$translated_text = 'Email Address'; | |
} | |
if ($translated_text === 'Please enter your username or email address. You will receive a link to create a new password via email.') { | |
$translated_text = 'Please enter your email address. You will receive a link to create a new password via email.'; | |
} | |
return $translated_text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment