is_email_address_unsafe

函数
is_email_address_unsafe ( $user_email )
参数
  • (string) $user_email The email provided by the user at registration.
    Required:
返回值
  • (bool) True when the email address is banned, false otherwise.
定义位置
相关方法
rest_is_ip_addressget_blogaddress_by_nameoptions_permalink_add_jsoptions_general_add_jsoptions_reading_add_js
引入
-
弃用
-

is_email_address_unsafe: 这个函数检查一个给定的电子邮件地址是否被认为不安全。它根据已知的不安全的电子邮件地址列表进行检查,如果电子邮件地址是不安全的,则返回真,如果不是则返回假。

根据被禁止的域名列表检查一个电子邮件地址。

该函数根据wp-admin/network/settings.php中的禁止邮件域名列表进行检查。该检查仅在自我注册时运行;在wp-admin/network/users.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 ( substr( $normalized_email, -strlen( $dotted_domain ) ) === $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 );
}

常见问题

FAQs
查看更多 >