Make WordPress Core

Changeset 61495


Ignore:
Timestamp:
01/17/2026 06:38:20 AM (5 weeks ago)
Author:
westonruter
Message:

Administration: Avoid PHP type error with gmdate() in wp_dashboard_recent_posts().

This fixes an issue when a non-integer is returned by get_the_time( 'U' ) which can occur when a plugin filters get_the_time. In this case, the non-relative date is displayed in the Activity dashboard widget.

Developed in https://github.com/WordPress/wordpress-develop/pull/10729

Follow-up to [26690], [26242].

Props sabernhardt, vanhoucke, westonruter.
Fixes #64496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r61192 r61495  
    10151015            $time = get_the_time( 'U' );
    10161016
    1017             if ( gmdate( 'Y-m-d', $time ) === $today ) {
    1018                 $relative = __( 'Today' );
     1017            if ( ! is_int( $time ) ) {
     1018                /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
     1019                $date = get_the_date( __( 'M jS Y' ) );
     1020            } elseif ( gmdate( 'Y-m-d', $time ) === $today ) {
     1021                $date = __( 'Today' );
    10191022            } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
    1020                 $relative = __( 'Tomorrow' );
     1023                $date = __( 'Tomorrow' );
    10211024            } elseif ( gmdate( 'Y', $time ) !== $year ) {
    10221025                /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
    1023                 $relative = date_i18n( __( 'M jS Y' ), $time );
     1026                $date = date_i18n( __( 'M jS Y' ), $time );
    10241027            } else {
    10251028                /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */
    1026                 $relative = date_i18n( __( 'M jS' ), $time );
     1029                $date = date_i18n( __( 'M jS' ), $time );
    10271030            }
    10281031
     
    10341037                '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
    10351038                /* translators: 1: Relative date, 2: Time. */
    1036                 sprintf( _x( '%1$s, %2$s', 'dashboard' ), $relative, get_the_time() ),
     1039                sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ),
    10371040                $recent_post_link,
    10381041                /* translators: %s: Post title. */
Note: See TracChangeset for help on using the changeset viewer.