Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created September 9, 2022 13:46
Show Gist options
  • Save nikitasinelnikov/b01907be1d4af79601bbf64d9c2ffea8 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/b01907be1d4af79601bbf64d9c2ffea8 to your computer and use it in GitHub Desktop.
Ultimate Member v3: Password Reset. Lost Password form validation using Email Address only
function um_021522_form_notice( $text, $key ) {
if ( 'lostpassword-info' === $key ) {
$text = __( 'Please enter your email address. You will receive an email message with instructions on how to reset your password.', 'ultimate-member' );
}
return $text;
}
add_filter( 'um_form_notice', 'um_021522_form_notice', 10, 2 );
function um_021522_lostpassword_form_args( $lostpassword_args ) {
foreach ( $lostpassword_args['fields'] as &$field_data ) {
if ( 'user_login' === $field_data['id'] ) {
$field_data['label'] = __( 'Email Address', 'ultimate-member' );
$field_data['placeholder'] = __( 'Enter Email Address', 'ultimate-member' );
}
}
return $lostpassword_args;
}
add_filter( 'um_lostpassword_form_args', 'um_021522_lostpassword_form_args', 10, 1 );
function um_021522_reset_password_error( $lostpassword_form ) {
if ( ! empty( $_POST['user_login'] ) ) {
$user_login = sanitize_text_field( wp_unslash( $_POST['user_login'] ) );
if ( ! is_email( $user_login ) ) {
$lostpassword_form->add_error( 'user_login', __( 'Please provide your email address.', 'ultimate-member' ) );
}
}
}
add_action( 'um_lostpassword_errors_hook', 'um_021522_reset_password_error', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment