Make WordPress Core


Ignore:
Timestamp:
06/16/2018 10:42:16 AM (6 years ago)
Author:
SergeyBiryukov
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.
Merges [42726], [42728], and [43356] to the 4.9 branch.
Fixes #41112.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/class-wp-community-events.php

    r43082 r43357  
    386386
    387387    /**
    388      * Discards expired events, and reduces the remaining list.
    389      *
    390      * @since 4.8.0
     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.
     396     *
     397     * @since 4.8.0
     398     * @since 4.9.7 Stick a WordCamp to the final list.
    391399     *
    392400     * @param  array $response_body The response body which contains the events.
     
    395403    protected function trim_events( $response_body ) {
    396404        if ( isset( $response_body['events'] ) ) {
     405            $wordcamps         = array();
    397406            $current_timestamp = current_time( 'timestamp' );
    398407
    399408            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;
    402415                    continue;
    403416                }
     
    411424
    412425            $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            }
    413433        }
    414434
Note: See TracChangeset for help on using the changeset viewer.