diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index e956642b91..e88713425b 100644 --- a/src/wp-includes/general-template.php +++ b/src/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/tests/phpunit/tests/date/theDate.php b/tests/phpunit/tests/date/theDate.php index 54fecdffb6..31bc89e90b 100644 --- a/tests/phpunit/tests/date/theDate.php +++ b/tests/phpunit/tests/date/theDate.php @@ -81,4 +81,72 @@ class Tests_Date_TheDate extends WP_UnitTestCase { return $input; } + + /** + * @ticket 33750 + */ + function test_the_date() { + ob_start(); + the_date(); + $actual = ob_get_clean(); + $this->assertEquals( '', $actual ); + + $GLOBALS['post'] = self::factory()->post->create_and_get( + array( + 'post_date' => '2015-09-16 08:00:00', + ) + ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date(); + $this->assertEquals( 'September 16, 2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y' ); + $this->assertEquals( '2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after' ); + $this->assertEquals( 'before 2015 after', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after', false ); + $this->assertEquals( '', ob_get_clean() ); + } + + /** + * @ticket 47354 + */ + function test_the_weekday_date() { + ob_start(); + the_weekday_date(); + $actual = ob_get_clean(); + $this->assertEquals( '', $actual ); + + $GLOBALS['post'] = self::factory()->post->create_and_get( + array( + 'post_date' => '2015-09-16 08:00:00', + ) + ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_weekday_date(); + $this->assertEquals( 'Wednesday', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_weekday_date( 'before ', ' after' ); + $this->assertEquals( 'before Wednesday after', ob_get_clean() ); + } } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 88b9a46475..1013931dd5 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -915,46 +915,6 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertFalse( $json ); } - /** - * @ticket 33750 - */ - function test_the_date() { - ob_start(); - the_date(); - $actual = ob_get_clean(); - $this->assertEquals( '', $actual ); - - $GLOBALS['post'] = self::factory()->post->create_and_get( - array( - 'post_date' => '2015-09-16 08:00:00', - ) - ); - - ob_start(); - $GLOBALS['currentday'] = '18.09.15'; - $GLOBALS['previousday'] = '17.09.15'; - the_date(); - $this->assertEquals( 'September 16, 2015', ob_get_clean() ); - - ob_start(); - $GLOBALS['currentday'] = '18.09.15'; - $GLOBALS['previousday'] = '17.09.15'; - the_date( 'Y' ); - $this->assertEquals( '2015', ob_get_clean() ); - - ob_start(); - $GLOBALS['currentday'] = '18.09.15'; - $GLOBALS['previousday'] = '17.09.15'; - the_date( 'Y', 'before ', ' after' ); - $this->assertEquals( 'before 2015 after', ob_get_clean() ); - - ob_start(); - $GLOBALS['currentday'] = '18.09.15'; - $GLOBALS['previousday'] = '17.09.15'; - the_date( 'Y', 'before ', ' after', false ); - $this->assertEquals( '', ob_get_clean() ); - } - /** * @ticket 36054 * @dataProvider datetime_provider