Block certain email domains from registering

This function will block certain email domains from registering your site.

Make sure to:

  • add what domains to block in $list_of_blocked_domains on line 6

wppb_check_form_field_default-e-mail is located in Profile Builder: /front-end/default-fields/email/email.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * Block certain email domains from registering
 */
 
function wppb_check_email_domain( $message, $field, $request_data, $form_location ){
   $list_of_blocked_domains = array( 'domain.com', 'mail.com', );
   //$domain = array_pop(explode('@', $request_data['email']));
   $domain = substr(strrchr($request_data['email'], "@"), 1);
   if ( in_array( $domain, $list_of_blocked_domains) ) {
      return __( 'The email domain you entered is not allowed on this website. Please try with a different email address.', 'profilebuilder' );
   }
 
   return $message;
}
add_filter( 'wppb_check_form_field_default-e-mail', 'wppb_check_email_domain', 20, 4 );