Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created July 23, 2022 23:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hivepress/64e25bdbdb2d2cf48099eaf625e9e2c5 to your computer and use it in GitHub Desktop.
Save hivepress/64e25bdbdb2d2cf48099eaf625e9e2c5 to your computer and use it in GitHub Desktop.
Restrict email domains for newly registered users #hivepress #users
<?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