Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allow email only for WordPress password reset requests
// 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
You can’t perform that action at this time.