Created
January 21, 2025 18:00
-
-
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.
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
<?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' ) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.