is_email_address_unsafe()判断用户地址是否安全

目录

描述

Checks an email address against a list of banned domains.

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.

As of 3.5, this function was made marginally less aggressive due to legitimate domains matching as partials of banned domains or sub-domains of banned domains.

is_email_address_unsafe() 描述

用法

<?php is_email_address_unsafe$user_email ); ?>

is_email_address_unsafe() 用法

参数

$user_email

(string) (必填) The email provided by the user at registration.

默认值: None

is_email_address_unsafe() 参数

返回值

(bool

Returns true when the email address is banned.

is_email_address_unsafe() 返回值

源文件

is_email_address_unsafe() 函数的代码位于 wp-includes/ms-functions.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Checks an email address against a list of banned domains.
 *
 * 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.
 *
 * @since MU
 *
 * @param string $user_email The email provided by the user at registration.
 * @return bool Returns true when the email address is banned.
 */
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( "
", $banned_names );

	$is_email_address_unsafe = false;

	if ( $banned_names && is_array( $banned_names ) ) {
		$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;
			}
		}
	}

	/**
	 * Filter 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 );
}

is_email_address_unsafe() 源文件