WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Community_Events::format_event_data_time() protected WP 4.8.0

Adds formatted date and time items for each event in an API response.

This has to be called after the data is pulled from the cache, because the cached events are shared by all users. If it was called before storing the cache, then all users would see the events in the localized data/time of the user who triggered the cache refresh, rather than their own.

Это метод класса: WP_Community_Events{}

Хуков нет.

Возвращает

Массив. The response with dates and times formatted.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->format_event_data_time( $response_body );
$response_body(массив) (обязательный)
The response which contains the events.

Список изменений

С версии 4.8.0 Введена.

Код WP_Community_Events::format_event_data_time() WP 5.5.1

wp-admin/includes/class-wp-community-events.php
<?php
protected function format_event_data_time( $response_body ) {
	if ( isset( $response_body['events'] ) ) {
		foreach ( $response_body['events'] as $key => $event ) {
			$timestamp = strtotime( $event['date'] );

			/*
			 * The `date_format` option is not used because it's important
			 * in this context to keep the day of the week in the formatted date,
			 * so that users can tell at a glance if the event is on a day they
			 * are available, without having to open the link.
			 */
			/* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/date */
			$formatted_date = date_i18n( __( 'l, M j, Y' ), $timestamp );
			$formatted_time = date_i18n( get_option( 'time_format' ), $timestamp );

			if ( isset( $event['end_date'] ) ) {
				$end_timestamp      = strtotime( $event['end_date'] );
				$formatted_end_date = date_i18n( __( 'l, M j, Y' ), $end_timestamp );

				if ( 'meetup' !== $event['type'] && $formatted_end_date !== $formatted_date ) {
					/* translators: Upcoming events month format. See https://www.php.net/date */
					$start_month = date_i18n( _x( 'F', 'upcoming events month format' ), $timestamp );
					$end_month   = date_i18n( _x( 'F', 'upcoming events month format' ), $end_timestamp );

					if ( $start_month === $end_month ) {
						$formatted_date = sprintf(
							/* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */
							__( '%1$s %2$d–%3$d, %4$d' ),
							$start_month,
							/* translators: Upcoming events day format. See https://www.php.net/date */
							date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
							date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
							/* translators: Upcoming events year format. See https://www.php.net/date */
							date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
						);
					} else {
						$formatted_date = sprintf(
							/* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Year. */
							__( '%1$s %2$d – %3$s %4$d, %5$d' ),
							$start_month,
							date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
							$end_month,
							date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
							date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
						);
					}

					$formatted_date = wp_maybe_decline_date( $formatted_date, 'F j, Y' );
				}
			}

			$response_body['events'][ $key ]['formatted_date'] = $formatted_date;
			$response_body['events'][ $key ]['formatted_time'] = $formatted_time;
		}
	}

	return $response_body;
}