wpcf7_is_mailbox_list()CF7 1.0

Checks whether the given text is a well-formed mailbox list.

Хуков нет.

Возвращает

Массив|true|false. Array of email addresses if all items are well-formed mailbox, false if not.

Использование

wpcf7_is_mailbox_list( $mailbox_list );
$mailbox_list(строка|массив) (обязательный)
The subject to be checked. Comma-separated string or an array of mailboxes.

Код wpcf7_is_mailbox_list() CF7 5.6.2

function wpcf7_is_mailbox_list( $mailbox_list ) {
	if ( ! is_array( $mailbox_list ) ) {
		$mailbox_text = (string) $mailbox_list;

		$mailbox_text = preg_replace(
			'/\\\\(?:\"|\')/',
			'esc-quote',
			$mailbox_text
		);

		$mailbox_text = preg_replace(
			'/(?:\".*?\"|\'.*?\')/',
			'quoted-string',
			$mailbox_text
		);

		$mailbox_list = explode( ',', $mailbox_text );
	}

	$addresses = array();

	foreach ( $mailbox_list as $mailbox ) {
		if ( ! is_string( $mailbox ) ) {
			return false;
		}

		$mailbox = trim( $mailbox );

		if ( '' === $mailbox ) {
			continue;
		}

		if ( preg_match( '/<(.+)>$/', $mailbox, $matches ) ) {
			$addr_spec = $matches[1];
		} else {
			$addr_spec = $mailbox;
		}

		if ( ! wpcf7_is_email( $addr_spec ) ) {
			return false;
		}

		$addresses[] = $addr_spec;
	}

	return $addresses;
}