Created
July 23, 2022 23:24
-
-
Save hivepress/64e25bdbdb2d2cf48099eaf625e9e2c5 to your computer and use it in GitHub Desktop.
Restrict email domains for newly registered users #hivepress #users
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 | |
add_filter( | |
'hivepress/v1/forms/user_register/errors', | |
function( $errors, $form ) { | |
if ( ! $errors ) { | |
$domain = hivepress()->helper->get_last_array_value( explode( '@', $form->get_value( 'email' ) ) ); | |
if ( ! in_array( | |
$domain, | |
[ | |
'gmail.com', | |
'yahoo.com', | |
'outlook.com', | |
] | |
) ) { | |
$errors[] = 'This email domain is not allowed.'; | |
} | |
} | |
return $errors; | |
}, | |
1000, | |
2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment