Skip to content

Commit 343fa03

Browse files
committed
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 #10729 Follow-up to [26690], [26242]. Props sabernhardt, vanhoucke, westonruter. Fixes #64496. git-svn-id: https://develop.svn.wordpress.org/trunk@61495 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6346429 commit 343fa03

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/wp-admin/includes/dashboard.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,16 +1014,19 @@ function wp_dashboard_recent_posts( $args ) {
10141014

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

10291032
// Use the post edit link for those who can edit, the permalink otherwise.
@@ -1033,7 +1036,7 @@ function wp_dashboard_recent_posts( $args ) {
10331036
printf(
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. */
10391042
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),

0 commit comments

Comments
 (0)