Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active June 18, 2025 06:37
Show Gist options
  • Save yuriinalivaiko/11e0530f4329b63e817b844b3fd9320f to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/11e0530f4329b63e817b844b3fd9320f to your computer and use it in GitHub Desktop.
Ultimate Member customization. Change error message for the "E-mail Address" field in the Registration form.
<?php
/**
* Custom validation and error message for the "E-mail Address" field.
*/
add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 999, 3 );
function um_custom_validate_user_email_details( $key, $array, $args ) {
if ( $key == 'user_email' && isset( $args['user_email'] ) ) {
if ( isset( UM()->form()->errors['user_email'] ) ) {
unset( UM()->form()->errors['user_email'] );
}
if ( empty( $args['user_email'] ) ) {
UM()->form()->add_error( 'user_email', __( 'E-mail Address is required', 'ultimate-member' ) );
} elseif ( ! is_email( $args['user_email'] ) ) {
UM()->form()->add_error( 'user_email', __( 'The email you entered is invalid', 'ultimate-member' ) );
} elseif ( email_exists( $args['user_email'] ) ) {
UM()->form()->add_error( 'user_email', __( 'The email you entered is already registered', 'ultimate-member' ) );
}
}
}
@yuriinalivaiko
Copy link
Author

yuriinalivaiko commented Jan 15, 2023

You can use the Custom Validation option to change the error message for the E-mail Address field in the Registration form. The custom_field_validation_user_email.php code snippet is an example for validation based on the Custom Validation option.

See articles Fields Validation and Custom validation email and error message in registration for details.

@BlackStar1991
Copy link

I got a problem with last elseif ( email_exists( $args['user_email'] ) ) I already has email in DB but got message - "The email you entered is invalid"

@jinayt
Copy link

jinayt commented Jun 18, 2025

elseif ( ! is_email( $args['user_email'] ) ) {
UM()->form()->add_error( 'user_email', __( 'The email you entered is invalid', 'ultimate-member' ) );
}
not working

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