根据禁止域列表检查电子邮件地址。

原型

is_email_address_unsafe( string $user_email )

描述

此功能将检查wp-admin / network / settings.php中的禁止电子邮件域列表。支票只在自行注册时运行;在wp-admin / network / users.php创建用户可以绕过此检查。

参数

$user_email (string) (Required) 用户在注册时提供的电子邮件。

返回值

(bool)  禁止电子邮件地址时返回true。

源文件

路径:wp-includes/ms-functions.php

<?php
...
function is_email_address_unsafe( $user_email ) {
	$banned_names = get_site_option( 'banned_email_domains' );
	if ( $banned_names && ! is_array( $banned_names ) )
		$banned_names = explode( "n", $banned_names );
	$is_email_address_unsafe = false;
	if ( $banned_names && is_array( $banned_names ) && false !== strpos( $user_email, '@', 1 ) ) {
		$banned_names = array_map( 'strtolower', $banned_names );
		$normalized_email = strtolower( $user_email );
		list( $email_local_part, $email_domain ) = explode( '@', $normalized_email );
		foreach ( $banned_names as $banned_domain ) {
			if ( ! $banned_domain )
				continue;
			if ( $email_domain == $banned_domain ) {
				$is_email_address_unsafe = true;
				break;
			}
			$dotted_domain = ".$banned_domain";
			if ( $dotted_domain === substr( $normalized_email, -strlen( $dotted_domain ) ) ) {
				$is_email_address_unsafe = true;
				break;
			}
		}
	}
	/**
	 * Filters whether an email address is unsafe.
	 *
	 * @since 3.5.0
	 *
	 * @param bool   $is_email_address_unsafe Whether the email address is "unsafe". Default false.
	 * @param string $user_email              User email address.
	 */
	return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/is_email_address_unsafe/