Last active
March 2, 2017 14:53
-
-
Save brocheafoin/9bf171cca8675d75c61f to your computer and use it in GitHub Desktop.
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
add_action( 'um_before_new_user_register', 'require_whitelisted_email_for_signup' ); | |
function require_whitelisted_email_for_signup( $args ) { | |
$user_email = $args['user_email']; | |
$approved_domains = array( 'yahoo.com', 'gmail.com', 'hotmail.com' ); | |
$email_approved = false; | |
foreach ( $approved_domains as $domain ) { | |
$prefixed_domain = '@' . $domain; | |
if ( str_ends_with( $user_email, $prefixed_domain ) ) { | |
$email_approved = true; | |
break; | |
} | |
} | |
if ( ! $email_approved ) { | |
exit( wp_safe_redirect( add_query_arg( 'err', 'blocked_domain' ) ) ); | |
} | |
} | |
function str_ends_with( $haystack, $needle ) { | |
$needle_position = strripos( $haystack, $needle, - 1 ); // -1 = Look at the exact end | |
$needle_expected_position = strlen( $haystack ) - strlen( $needle ); // length of the haystack minus length of the needle = beginning of the needle in the haystack | |
return ( $needle_position === $needle_expected_position ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loving it! 😄