Last active
December 7, 2023 12:19
-
-
Save denisbaranov/27b74695ed671cb286a3efb48aa6aba6 to your computer and use it in GitHub Desktop.
The following code requires @gmail.com as an email domain for user registrations. You can change @gmail.com to any provider you want. The code below requires a user email to be collected during registration.
This file contains 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 | |
/** | |
* This example shows how to validate the email address by domain on registration. | |
* The code below requires a user email to be collected during registration. | |
* | |
* Change the array $allowed_email_domains - add or remove what you need. | |
* Add this code snippet to the end of the file functions.php in the active theme directory. | |
* | |
* Ultimate Member documentation: https://docs.ultimatemember.com/ | |
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/ | |
*/ | |
/** | |
* Custom validation for the field "E-mail Address" by domain on registration. | |
* @author Ultimate Member support <support@ultimatemember.com> | |
* @param array $args | |
*/ | |
function um_validate_email_domain( $args ) { | |
// Change allowed email domains here | |
$allowed_email_domains = apply_filters( 'um_allowed_email_domains', array( | |
'gmail.com', | |
'yahoo.com', | |
'hotmail.com' | |
) ); | |
// Change error message here | |
$message = __( 'You can not use this email domain for registration', 'ultimate-member' ); | |
if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) { | |
$email_domain = array_pop( explode( '@', trim( $args['user_email'] ) ) ); | |
if ( !in_array( $email_domain, $allowed_email_domains ) ) { | |
UM()->form()->add_error( 'user_email', $message ); | |
} | |
} | |
} | |
add_action( 'um_submit_form_errors_hook__registration', 'um_validate_email_domain', 20 ); |
alemacks
commented
Mar 6, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment