is_email_address_unsafe

Checks an email address against a list of banned domains.

Description

is_email_address_unsafe( (string) $user_email ); 

This function checks against the Banned Email Domains list at wp-admin/network/settings.php. The check is only run on self-registrations; user creation at wp-admin/network/users.php bypasses this check.

Parameters (1)

0. $user_email (string)
The email provided by the user at registration.

Usage

  1. if ( !function_exists( 'is_email_address_unsafe' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The email provided by the user at registration. 
  5. $user_email = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_email_address_unsafe($user_email); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function is_email_address_unsafe( $user_email ) { 
  2. $banned_names = get_site_option( 'banned_email_domains' ); 
  3. if ( $banned_names && ! is_array( $banned_names ) ) 
  4. $banned_names = explode( "\n", $banned_names ); 
  5.  
  6. $is_email_address_unsafe = false; 
  7.  
  8. if ( $banned_names && is_array( $banned_names ) ) { 
  9. $banned_names = array_map( 'strtolower', $banned_names ); 
  10. $normalized_email = strtolower( $user_email ); 
  11.  
  12. list( $email_local_part, $email_domain ) = explode( '@', $normalized_email ); 
  13.  
  14. foreach ( $banned_names as $banned_domain ) { 
  15. if ( ! $banned_domain ) 
  16. continue; 
  17.  
  18. if ( $email_domain == $banned_domain ) { 
  19. $is_email_address_unsafe = true; 
  20. break; 
  21.  
  22. $dotted_domain = ".$banned_domain"; 
  23. if ( $dotted_domain === substr( $normalized_email, -strlen( $dotted_domain ) ) ) { 
  24. $is_email_address_unsafe = true; 
  25. break; 
  26.  
  27. /** 
  28. * Filters whether an email address is unsafe. 
  29. * @since 3.5.0 
  30. * @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false. 
  31. * @param string $user_email User email address. 
  32. */ 
  33. return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );