From 16c43f368d8a7cf9b3ca5cad7e90fd5c1ecfe782 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 29 Aug 2019 23:18:55 +0000 Subject: [PATCH] Date/Time: Restore the previous behavior of `date_i18n()` where invalid input would result in current time. Make `wp_date()` return `false` on invalid timestamp input, for consistency with upstream PHP `date()` function. Props Rarst. Fixes #28636. Built from https://develop.svn.wordpress.org/trunk@45914 git-svn-id: http://core.svn.wordpress.org/trunk@45725 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 8a7897a909..3acfe7318e 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -163,8 +163,12 @@ function wp_timezone() { * @return string The date, translated if locale specifies it. */ function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) { + $timestamp = $timestamp_with_offset; + // If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true). - $timestamp = $timestamp_with_offset ? $timestamp_with_offset : current_time( 'timestamp', $gmt ); + if ( ! is_numeric( $timestamp ) ) { + $timestamp = current_time( 'timestamp', $gmt ); + } /* * This is a legacy implementation quirk that the returned timestamp is also with offset. @@ -218,13 +222,15 @@ function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) { * @param int $timestamp Optional. Unix timestamp. Defaults to current time. * @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone * from site settings. - * @return string The date, translated if locale specifies it. + * @return string|false The date, translated if locale specifies it. False on invalid timestamp input. */ function wp_date( $format, $timestamp = null, $timezone = null ) { global $wp_locale; - if ( ! $timestamp ) { + if ( null === $timestamp ) { $timestamp = time(); + } elseif ( ! is_numeric( $timestamp ) ) { + return false; } if ( ! $timezone ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c63586ae5d..5f3d8ba250 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45913'; +$wp_version = '5.3-alpha-45914'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.