GC_Community_Events::trim_events()
最后更新于:2021-11-26 23:08:11
GC_Community_Events::trim_events( array$events)Prepares the event list for presentation.
参数
- $events
-
(array) (Required) The events that will be prepared.
响应
(array) The response body with events trimmed.
源文件
文件: gc-admin/includes/class-gc-community-events.php
protected function trim_events( array $events ) {
$future_events = array();
foreach ( $events as $event ) {
/*
* The API's `date` and `end_date` fields are in the _event's_ local timezone, but UTC is needed so
* it can be converted to the _user's_ local time.
*/
$end_time = (int) $event['end_unix_timestamp'];
if ( time() < $end_time ) {
array_push( $future_events, $event );
}
}
$future_wordcamps = array_filter(
$future_events,
function( $wordcamp ) {
return 'wordcamp' === $wordcamp['type'];
}
);
$future_wordcamps = array_values( $future_wordcamps ); // Remove gaps in indices.
$trimmed_events = array_slice( $future_events, 0, 3 );
$trimmed_event_types = gc_list_pluck( $trimmed_events, 'type' );
// Make sure the soonest upcoming WordCamp is pinned in the list.
if ( $future_wordcamps && ! in_array( 'wordcamp', $trimmed_event_types, true ) ) {
array_pop( $trimmed_events );
array_push( $trimmed_events, $future_wordcamps[0] );
}
return $trimmed_events;
}