Making WordPress.org

Changeset 12667


Ignore:
Timestamp:
06/20/2023 10:24:08 AM (3 years ago)
Author:
renyot
Message:

Official WordPress Events: Sort online events list by UTC time

See https://meta.trac.wordpress.org/ticket/7071
See https://github.com/WordPress/wordpress.org/pull/158

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-events-online.php

    r9787 r12667  
    3939        // The `date_utc` is not actually a UTC timestamp, it's the local time as Y-m-d H:i:s.
    4040        // We need to convert it back to UTC by subtracting the UTC offset.
    41         $timestamp = strtotime( $event->date_utc ) - $event->date_utc_offset;
     41        $timestamp       = strtotime( $event->date_utc ) - $event->date_utc_offset;
    4242        $cached_events[] = array(
    4343            'title'           => $event->title,
     
    4646        );
    4747    }
     48
     49    // As the original data was sorted by local time (`date_utc`),
     50    // we need to reorder the events after it's converted back to UTC.
     51    usort(
     52        $cached_events,
     53        function( $a, $b ) {
     54            return $a['start_timestamp'] <=> $b['start_timestamp'];
     55        }
     56    );
    4857
    4958    return $cached_events;
     
    8493 */
    8594function render_online_templates() {
    86     require_once( __DIR__ . '/template-events-online.php' );
     95    require_once __DIR__ . '/template-events-online.php';
    8796}
    8897
Note: See TracChangeset for help on using the changeset viewer.