388
* Discards expired events, and reduces the remaining list.
388
* Prepares the event list for presentation.
390
* Discards expired events, and makes WordCamps "sticky." Attendees need more
391
* advanced notice about WordCamps than they do for meetups, so camps should
392
* appear in the list sooner. If a WordCamp is coming up, the API will "stick"
393
* it in the response, even if it wouldn't otherwise appear. When that happens,
394
* the event will be at the end of the list, and will need to be moved into a
395
* higher position, so that it doesn't get trimmed off.
398
* @since 4.9.7 Stick a WordCamp to the final list.
392
400
* @param array $response_body The response body which contains the events.
393
401
* @return array The response body with events trimmed.
395
403
protected function trim_events( $response_body ) {
396
404
if ( isset( $response_body['events'] ) ) {
405
$wordcamps = array();
397
406
$current_timestamp = current_time( 'timestamp' );
399
408
foreach ( $response_body['events'] as $key => $event ) {
400
// Skip WordCamps, because they might be multi-day events.
401
if ( 'meetup' !== $event['type'] ) {
410
* Skip WordCamps, because they might be multi-day events.
411
* Save a copy so they can be pinned later.
413
if ( 'wordcamp' === $event['type'] ) {
414
$wordcamps[] = $event;
412
425
$response_body['events'] = array_slice( $response_body['events'], 0, 3 );
426
$trimmed_event_types = wp_list_pluck( $response_body['events'], 'type' );
428
// Make sure the soonest upcoming WordCamps is pinned in the list.
429
if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) {
430
array_pop( $response_body['events'] );
431
array_push( $response_body['events'], $wordcamps[0] );
415
435
return $response_body;