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. git-svn-id: https://develop.svn.wordpress.org/trunk@45378 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
36df800c3c
commit
48fb69f013
|
@ -2340,9 +2340,12 @@ 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.
|
||||
|
@ -2363,7 +2366,6 @@ function the_date( $d = '', $before = '', $after = '', $echo = true ) {
|
|||
return $the_date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the date on which the post was written.
|
||||
|
@ -2702,19 +2704,21 @@ function the_weekday() {
|
|||
*
|
||||
* @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 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue