WP_Community_Events::format_event_data_time( array $response_body )

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


Description Description

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.


Parameters Parameters

$response_body

(array) (Required) The response which contains the events.


Top ↑

Return Return

(array) The response with dates and times formatted.


Top ↑

Source Source

File: wp-admin/includes/class-wp-community-events.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://secure.php.net/date. */
				$response_body['events'][ $key ]['formatted_date'] = date_i18n( __( 'l, M j, Y' ), $timestamp );
				$response_body['events'][ $key ]['formatted_time'] = date_i18n( get_option( 'time_format' ), $timestamp );
			}
		}

		return $response_body;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.