bp_core_validate_email_address

Check that an email address is valid for use.

Description

(bool|array) bp_core_validate_email_address( (string) $user_email ); 

Performs the following checks: - Is the email address well-formed? - Is the email address already used? - If there's an email domain blacklist, is the current domain on it? - If there's an email domain whitelest, is the current domain on it?

Returns (bool|array)

True if the address passes all checks; otherwise an array of error codes.

Parameters (1)

0. $user_email (string)
The email being checked.

Usage

  1. if ( !function_exists( 'bp_core_validate_email_address' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // The email being checked. 
  5. $user_email = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_validate_email_address($user_email); 
  9.  

Defined (1)

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

/bp-members/bp-members-functions.php  
  1. function bp_core_validate_email_address( $user_email ) { 
  2. $errors = array(); 
  3.  
  4. $user_email = sanitize_email( $user_email ); 
  5.  
  6. // Is the email well-formed? 
  7. if ( ! is_email( $user_email ) ) { 
  8. $errors['invalid'] = 1; 
  9.  
  10. // Is the email on the Banned Email Domains list? 
  11. // Note: This check only works on Multisite. 
  12. if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) { 
  13. $errors['domain_banned'] = 1; 
  14.  
  15. // Is the email on the Limited Email Domains list? 
  16. // Note: This check only works on Multisite. 
  17. $limited_email_domains = get_site_option( 'limited_email_domains' ); 
  18. if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { 
  19. $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); 
  20. if ( ! in_array( $emaildomain, $limited_email_domains ) ) { 
  21. $errors['domain_not_allowed'] = 1; 
  22.  
  23. // Is the email alreday in use? 
  24. if ( email_exists( $user_email ) ) { 
  25. $errors['in_use'] = 1; 
  26.  
  27. $retval = ! empty( $errors ) ? $errors : true; 
  28.  
  29. return $retval;