~canonical-sysadmins/wordpress/5.0.2

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-community-events.php

  • Committer: Barry Price
  • Date: 2018-07-06 10:06:19 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: barry.price@canonical.com-20180706100619-g8mbdb7wvr0aamb5
Merge WP4.9.7 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
385
385
        }
386
386
 
387
387
        /**
388
 
         * Discards expired events, and reduces the remaining list.
 
388
         * Prepares the event list for presentation.
 
389
         *
 
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.
389
396
         *
390
397
         * @since 4.8.0
 
398
         * @since 4.9.7 Stick a WordCamp to the final list.
391
399
         *
392
400
         * @param  array $response_body The response body which contains the events.
393
401
         * @return array The response body with events trimmed.
394
402
         */
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' );
398
407
 
399
408
                        foreach ( $response_body['events'] as $key => $event ) {
400
 
                                // Skip WordCamps, because they might be multi-day events.
401
 
                                if ( 'meetup' !== $event['type'] ) {
 
409
                                /*
 
410
                                 * Skip WordCamps, because they might be multi-day events.
 
411
                                 * Save a copy so they can be pinned later.
 
412
                                 */
 
413
                                if ( 'wordcamp' === $event['type'] ) {
 
414
                                        $wordcamps[] = $event;
402
415
                                        continue;
403
416
                                }
404
417
 
410
423
                        }
411
424
 
412
425
                        $response_body['events'] = array_slice( $response_body['events'], 0, 3 );
 
426
                        $trimmed_event_types     = wp_list_pluck( $response_body['events'], 'type' );
 
427
 
 
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] );
 
432
                        }
413
433
                }
414
434
 
415
435
                return $response_body;