WPCF7_FormTag::get_date_option()publicCF7 1.0

Retrieves a date-type option value from the form-tag.

Метод класса: WPCF7_FormTag{}

Хуки из метода

Возвращает

Строку|true|false. The option value in YYYY-MM-DD format. False if the option does not exist or the date value is invalid.

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

$WPCF7_FormTag = new WPCF7_FormTag();
$WPCF7_FormTag->get_date_option( $option_name );
$option_name(строка) (обязательный)
A date-type option name, such as 'min' or 'max'.

Код WPCF7_FormTag::get_date_option() CF7 5.6.4

public function get_date_option( $option_name ) {
	$option_value = $this->get_option( $option_name, '', true );

	if ( empty( $option_value ) ) {
		return false;
	}

	$date = apply_filters( 'wpcf7_form_tag_date_option',
		null,
		array( $option_name => $option_value )
	);

	if ( $date ) {
		$date_pattern = '/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/';

		if ( preg_match( $date_pattern, $date, $matches )
		and checkdate( $matches[2], $matches[3], $matches[1] ) ) {
			return $date;
		}
	} else {
		$datetime_obj = date_create_immutable(
			preg_replace( '/[_]+/', ' ', $option_value ),
			wp_timezone()
		);

		if ( $datetime_obj ) {
			return $datetime_obj->format( 'Y-m-d' );
		}
	}

	return false;
}