Summery Summery

Prepares the event list for presentation.

Syntax Syntax

WP_Community_Events::trim_events( array $response_body )

Description Description

Discards expired events, and makes WordCamps "sticky." Attendees need more advanced notice about WordCamps than they do for meetups, so camps should appear in the list sooner. If a WordCamp is coming up, the API will "stick" it in the response, even if it wouldn’t otherwise appear. When that happens, the event will be at the end of the list, and will need to be moved into a higher position, so that it doesn’t get trimmed off.

Parameters Parameters


(Required) The response body which contains the events.

Return Return

(array) The response body with events trimmed.

Source Source

File: wp-admin/includes/class-wp-community-events.php

	protected function trim_events( $response_body ) {
		if ( isset( $response_body['events'] ) ) {
			$wordcamps = array();
			$today     = current_time( 'Y-m-d' );

			foreach ( $response_body['events'] as $key => $event ) {
				 * Skip WordCamps, because they might be multi-day events.
				 * Save a copy so they can be pinned later.
				if ( 'wordcamp' === $event['type'] ) {
					$wordcamps[] = $event;

				// We don't get accurate time with timezone from API, so we only take the date part (Y-m-d).
				$event_date = substr( $event['date'], 0, 10 );

				if ( $today > $event_date ) {
					unset( $response_body['events'][ $key ] );

			$response_body['events'] = array_slice( $response_body['events'], 0, 3 );
			$trimmed_event_types     = wp_list_pluck( $response_body['events'], 'type' );

			// Make sure the soonest upcoming WordCamp is pinned in the list.
			if ( ! in_array( 'wordcamp', $trimmed_event_types, true ) && $wordcamps ) {
				array_pop( $response_body['events'] );
				array_push( $response_body['events'], $wordcamps[0] );

		return $response_body;


Changelog Changelog

Version Description
4.9.7 Stick a WordCamp to the final list.
4.8.0 Introduced.


Leave a Reply