WP_Community_Events::trim_events( array $response_body )
Prepares the event list for presentation.
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
- $response_body
-
(array) (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(); $current_timestamp = current_time( 'timestamp' ); 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; continue; } $event_timestamp = strtotime( $event['date'] ); if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) { 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 ) && $wordcamps ) { array_pop( $response_body['events'] ); array_push( $response_body['events'], $wordcamps[0] ); } } return $response_body; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.9.7 | Stick a WordCamp to the final list. |
4.8.0 | Introduced. |