Make WordPress Core

Changeset 47124


Ignore:
Timestamp:
01/29/2020 02:17:41 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Dashboard: Improve the appearance of "WordPress Events and News" dashboard widget for multi-day events.

If an upcoming event spans over several days, this information is now properly reflected in the widget.

Props imath, casiepa, iandunn, hareesh-pillai, melchoyce, mapk, desrosj, audrasjb, SergeyBiryukov.
Fixes #47798.

File:
1 edited

Legend:

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

    r47122 r47124  
    377377                 */
    378378                /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://www.php.net/date */
    379                 $response_body['events'][ $key ]['formatted_date'] = date_i18n( __( 'l, M j, Y' ), $timestamp );
    380                 $response_body['events'][ $key ]['formatted_time'] = date_i18n( get_option( 'time_format' ), $timestamp );
     379                $formatted_date = date_i18n( __( 'l, M j, Y' ), $timestamp );
     380                $formatted_time = date_i18n( get_option( 'time_format' ), $timestamp );
     381
     382                if ( isset( $event['end_date'] ) ) {
     383                    $end_timestamp      = strtotime( $event['end_date'] );
     384                    $formatted_end_date = date_i18n( __( 'l, M j, Y' ), $end_timestamp );
     385
     386                    if ( 'meetup' !== $event['type'] && $formatted_end_date !== $formatted_date ) {
     387                        /* translators: Upcoming events month format. See https://www.php.net/date */
     388                        $start_month = date_i18n( _x( 'F', 'upcoming events month format' ), $timestamp );
     389                        $end_month   = date_i18n( _x( 'F', 'upcoming events month format' ), $end_timestamp );
     390
     391                        if ( $start_month === $end_month ) {
     392                            $formatted_date = sprintf(
     393                                /* translators: Date string for upcoming events. 1: Month, 2: Starting day, 3: Ending day, 4: Year. */
     394                                __( '%1$s %2$d–%3$d, %4$d' ),
     395                                $start_month,
     396                                /* translators: Upcoming events day format. See https://www.php.net/date */
     397                                date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
     398                                date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
     399                                /* translators: Upcoming events year format. See https://www.php.net/date */
     400                                date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
     401                            );
     402                        } else {
     403                            $formatted_date = sprintf(
     404                                /* translators: Date string for upcoming events. 1: Starting month, 2: Starting day, 3: Ending month, 4: Ending day, 5: Year. */
     405                                __( '%1$s %2$d – %3$s %4$d, %5$d' ),
     406                                $start_month,
     407                                date_i18n( _x( 'j', 'upcoming events day format' ), $timestamp ),
     408                                $end_month,
     409                                date_i18n( _x( 'j', 'upcoming events day format' ), $end_timestamp ),
     410                                date_i18n( _x( 'Y', 'upcoming events year format' ), $timestamp )
     411                            );
     412                        }
     413
     414                        $formatted_date = wp_maybe_decline_date( $formatted_date, 'F j, Y' );
     415                    }
     416                }
     417
     418                $response_body['events'][ $key ]['formatted_date'] = $formatted_date;
     419                $response_body['events'][ $key ]['formatted_time'] = $formatted_time;
    381420            }
    382421        }
Note: See TracChangeset for help on using the changeset viewer.