Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuriinalivaiko/29cd3a7e0508d7cecbf3d3d936f82bf5 to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/29cd3a7e0508d7cecbf3d3d936f82bf5 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Add validation and error message for the field in the Password Reset form.
<?php
/**
* Custom validation and error message for the "Password Reset" field.
*/
add_action( 'um_reset_password_errors_hook', 'um_custom_validate_reset_password_email', 20 );
function um_custom_validate_reset_password_email( $inputs ) {
if ( isset( $inputs['username_b'] ) ) {
if ( isset( UM()->form()->errors['username_b'] ) ) {
unset( UM()->form()->errors['username_b'] );
}
if ( empty( $inputs['username_b'] ) ) {
UM()->form()->add_error( 'username_b', __( 'E-mail Address is required', 'ultimate-member' ) );
} elseif ( ! is_email( $inputs['username_b'] ) ) {
UM()->form()->add_error( 'username_b', __( 'The email you entered is invalid', 'ultimate-member' ) );
} elseif ( ! email_exists( $inputs['username_b'] ) ) {
UM()->form()->add_error( 'username_b', __( 'The email you entered does not exist', 'ultimate-member' ) );
}
}
}
@yuriinalivaiko
Copy link
Author

You can use the um_reset_password_errors_hook hook to apply custom validation to the Password Reset form. The um_custom_validate_reset_password_email.php code snippet is an example for validating the Password Reset form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment