Last active
November 21, 2020 03:32
-
-
Save cryptexvinci/754425df8ea2df1b843ac2bad9e95cd0 to your computer and use it in GitHub Desktop.
Ultimate Member - Only use a Selected email domain for registration
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 | |
/** | |
* Ultimate member - Restrict registration based on email domain. | |
* URL: https://wordpress.org/support/topic/email-domain-restriction-at-registration/ | |
*/ | |
add_action( 'um_submit_form_errors_hook__registration', 'um_register_email_provider_restrict', 99 ); | |
function um_register_email_provider_restrict( $args ) { | |
// List the email providers you want to allow | |
$allowed_domains = array('@gmail.com', '@hey.com'); | |
// For each domain provider check if the domain provider is allowed for registration. | |
foreach( $allowed_domains as $domain ) { | |
if ( isset( $args['user_email'] ) ) { | |
if ( !strstr( $args['user_email'], $domain ) ) { | |
$message = sprintf( __( 'Only use the email domain %1$s, %2$s for registration', 'ultimate-member' ), $allowed_domains[0], $allowed_domains[1] ); | |
UM()->form()->add_error( 'user_email', $message ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment