Make WordPress Core


Ignore:
Timestamp:
02/21/2018 11:00:50 PM (7 years ago)
Author:
jorbin
Message:

Community Events Dashboard: Always show a WordCamp if one is coming up

WordCamps are celebrations of the local WordPress Community and once a local one is scheduled, people in that community should know it is coming. This adjusts the WordPress Events in the dashboard widgets to always display a WordCamp, even if there are multiple Meetups happening first.

Props iandunn, metalandcoffee, warmlaundry, alejandroxlopez, jorbin.
Fixes #41112.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-community-events.php

    r42343 r42726  
    417417
    418418    /**
    419      * Discards expired events, and reduces the remaining list.
    420      *
    421      * @since 4.8.0
     419     * Prepares the event list for presentation.
     420     *
     421     * Discards expired events, and makes WordCamps "sticky." Attendees need more
     422     * advanced notice about WordCamps than they do for meetups, so camps should
     423     * appear in the list sooner. If a WordCamp is coming up, the API will "stick"
     424     * it in the response, even if it wouldn't otherwise appear. When that happens,
     425     * the event will be at the end of the list, and will need to be moved into a
     426     * higher position, so that it doesn't get trimmed off.
     427     *
     428     * @since 4.8.0
     429     * @since 5.0.0 Stick a WordCamp to the final list.
    422430     *
    423431     * @param  array $response_body The response body which contains the events.
     
    426434    protected function trim_events( $response_body ) {
    427435        if ( isset( $response_body['events'] ) ) {
     436            $wordcamps         = array();
    428437            $current_timestamp = current_time( 'timestamp' );
    429438
    430439            foreach ( $response_body['events'] as $key => $event ) {
    431                 // Skip WordCamps, because they might be multi-day events.
    432                 if ( 'meetup' !== $event['type'] ) {
     440                /*
     441                 * Skip WordCamps, because they might be multi-day events.
     442                 * Save a copy so they can be pinned later.
     443                 */
     444                if ( 'wordcamp' === $event['type'] ) {
     445                    $wordcamps[] = $event;
    433446                    continue;
    434447                }
     
    442455
    443456            $response_body['events'] = array_slice( $response_body['events'], 0, 3 );
     457            $trimmed_event_types     = array_column( $response_body['events'], 'type' );
     458
     459            // Make sure the soonest upcoming WordCamps is pinned in the list.
     460            if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) {
     461                array_pop( $response_body['events'] );
     462                array_push( $response_body['events'], $wordcamps[0] );
     463            }
    444464        }
    445465
Note: See TracChangeset for help on using the changeset viewer.