From ed086437348fef4e6a54a8994bbdde70e53f39fd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 22 May 2019 21:58:50 +0000 Subject: [PATCH] Date/Time: Bring some consistency to `the_date()` and `the_weekday_date()`: * Make `the_date()` always apply the the filter and return a value. * Use `is_new_day()` in `the_weekday_date()`. * Add a unit test for `the_weekday_date()`. Fixes #47354. Built from https://develop.svn.wordpress.org/trunk@45378 git-svn-id: http://core.svn.wordpress.org/trunk@45189 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 53 +++++++++++++++++--------------- wp-includes/version.php | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index e956642b91..e88713425b 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2340,28 +2340,30 @@ function the_date_xml() { function the_date( $d = '', $before = '', $after = '', $echo = true ) { global $currentday, $previousday; + $the_date = ''; + if ( is_new_day() ) { $the_date = $before . get_the_date( $d ) . $after; $previousday = $currentday; + } - /** - * Filters the date a post was published for display. - * - * @since 0.71 - * - * @param string $the_date The formatted date string. - * @param string $d PHP date format. Defaults to 'date_format' option - * if not specified. - * @param string $before HTML output before the date. - * @param string $after HTML output after the date. - */ - $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); + /** + * Filters the date a post was published for display. + * + * @since 0.71 + * + * @param string $the_date The formatted date string. + * @param string $d PHP date format. Defaults to 'date_format' option + * if not specified. + * @param string $before HTML output before the date. + * @param string $after HTML output after the date. + */ + $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); - if ( $echo ) { - echo $the_date; - } else { - return $the_date; - } + if ( $echo ) { + echo $the_date; + } else { + return $the_date; } } @@ -2700,21 +2702,23 @@ function the_weekday() { * * @since 0.71 * - * @global WP_Locale $wp_locale The WordPress date and time locale object. - * @global string $currentday The day of the current post in the loop. - * @global string $previousweekday The day of the previous post in the loop. + * @global WP_Locale $wp_locale The WordPress date and time locale object. + * @global string $currentday The day of the current post in the loop. + * @global string $previousday The day of the previous post in the loop. * * @param string $before Optional. Output before the date. * @param string $after Optional. Output after the date. */ function the_weekday_date( $before = '', $after = '' ) { - global $wp_locale, $currentday, $previousweekday; + global $wp_locale, $currentday, $previousday; + $the_weekday_date = ''; - if ( $currentday != $previousweekday ) { + + if ( is_new_day() ) { $the_weekday_date .= $before; $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) ); $the_weekday_date .= $after; - $previousweekday = $currentday; + $previousday = $currentday; } /** @@ -2726,8 +2730,7 @@ function the_weekday_date( $before = '', $after = '' ) { * @param string $before The HTML to output before the date. * @param string $after The HTML to output after the date. */ - $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after ); - echo $the_weekday_date; + echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 6459238024..6498d504a1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45377'; +$wp_version = '5.3-alpha-45378'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.