Skip to content

Instantly share code, notes, and snippets.

@taricco
Created July 22, 2020 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taricco/addd9d0b9001987bb440338bdf55c9c0 to your computer and use it in GitHub Desktop.
Save taricco/addd9d0b9001987bb440338bdf55c9c0 to your computer and use it in GitHub Desktop.
/* https://wordpress.org/plugins/user-registration/ */
function ur_validate_user_email( $single_form_field, $data, $filter_hook, $form_id ) {
$value = isset( $data->value ) ? $data->value : '';
$whitelist = array( 'domain1.com', 'domain2.com', 'domain3.com' );
$parts = explode( '@', $value );
if( ! in_array( $parts[1], $whitelist ) ) {
add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {
return __( 'You may only register with an approved email address.', 'user-registration' );
});
}
}
add_action( 'user_registration_validate_user_email','ur_validate_user_email', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment