bp_core_validate_email_address( string $user_email )

Check that an email address is valid for use.


Description Description

Performs the following checks:

  • Is the email address well-formed?
  • Is the email address already used?
  • If there are disallowed email domains, is the current domain among them?
  • If there’s an email domain whitelest, is the current domain on it?

Top ↑

Parameters Parameters

$user_email

(string) (Required) The email being checked.


Top ↑

Return Return

(bool|array) True if the address passes all checks; otherwise an array of error codes.


Source Source

File: bp-members/bp-members-functions.php

function bp_core_validate_email_address( $user_email ) {
	$errors = array();

	$user_email = sanitize_email( $user_email );

	// Is the email well-formed?
	if ( ! is_email( $user_email ) ) {
		$errors['invalid'] = 1;
	}

	// Is the email on the Banned Email Domains list?
	// Note: This check only works on Multisite.
	if ( function_exists( 'is_email_address_unsafe' ) && is_email_address_unsafe( $user_email ) ) {
		$errors['domain_banned'] = 1;
	}

	// Is the email on the Limited Email Domains list?
	// Note: This check only works on Multisite.
	$limited_email_domains = get_site_option( 'limited_email_domains' );
	if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
		$emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
		if ( ! in_array( $emaildomain, $limited_email_domains ) ) {
			$errors['domain_not_allowed'] = 1;
		}
	}

	// Is the email alreday in use?
	if ( email_exists( $user_email ) ) {
		$errors['in_use'] = 1;
	}

	$retval = ! empty( $errors ) ? $errors : true;

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.6.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.