Date/Time: Return early from `the_weekday()` and `the_weekday_date()` if we're not in the loop.
Restore `$previousweekday` global usage in `the_weekday_date()`, so it could still be used simultaneously with `the_date()`. Partially reverts [45378]. See #47354. git-svn-id: https://develop.svn.wordpress.org/trunk@45379 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
48fb69f013
commit
2a163fa733
|
@ -2682,7 +2682,13 @@ function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translat
|
||||||
function the_weekday() {
|
function the_weekday() {
|
||||||
global $wp_locale;
|
global $wp_locale;
|
||||||
|
|
||||||
$the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
|
$post = get_post();
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the weekday on which the post was written, for display.
|
* Filters the weekday on which the post was written, for display.
|
||||||
|
@ -2704,21 +2710,27 @@ function the_weekday() {
|
||||||
*
|
*
|
||||||
* @global WP_Locale $wp_locale The WordPress date and time locale object.
|
* @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 $currentday The day of the current post in the loop.
|
||||||
* @global string $previousday The day of the previous post in the loop.
|
* @global string $previousweekday The day of the previous post in the loop.
|
||||||
*
|
*
|
||||||
* @param string $before Optional. Output before the date.
|
* @param string $before Optional. Output before the date.
|
||||||
* @param string $after Optional. Output after the date.
|
* @param string $after Optional. Output after the date.
|
||||||
*/
|
*/
|
||||||
function the_weekday_date( $before = '', $after = '' ) {
|
function the_weekday_date( $before = '', $after = '' ) {
|
||||||
global $wp_locale, $currentday, $previousday;
|
global $wp_locale, $currentday, $previousweekday;
|
||||||
|
|
||||||
|
$post = get_post();
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$the_weekday_date = '';
|
$the_weekday_date = '';
|
||||||
|
|
||||||
if ( is_new_day() ) {
|
if ( $currentday !== $previousweekday ) {
|
||||||
$the_weekday_date .= $before;
|
$the_weekday_date .= $before;
|
||||||
$the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
|
$the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
|
||||||
$the_weekday_date .= $after;
|
$the_weekday_date .= $after;
|
||||||
$previousday = $currentday;
|
$previousweekday = $currentday;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -139,13 +139,13 @@ class Tests_Date_TheDate extends WP_UnitTestCase {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$GLOBALS['currentday'] = '18.09.15';
|
$GLOBALS['currentday'] = '18.09.15';
|
||||||
$GLOBALS['previousday'] = '17.09.15';
|
$GLOBALS['previousweekday'] = '17.09.15';
|
||||||
the_weekday_date();
|
the_weekday_date();
|
||||||
$this->assertEquals( 'Wednesday', ob_get_clean() );
|
$this->assertEquals( 'Wednesday', ob_get_clean() );
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$GLOBALS['currentday'] = '18.09.15';
|
$GLOBALS['currentday'] = '18.09.15';
|
||||||
$GLOBALS['previousday'] = '17.09.15';
|
$GLOBALS['previousweekday'] = '17.09.15';
|
||||||
the_weekday_date( 'before ', ' after' );
|
the_weekday_date( 'before ', ' after' );
|
||||||
$this->assertEquals( 'before Wednesday after', ob_get_clean() );
|
$this->assertEquals( 'before Wednesday after', ob_get_clean() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue