WordPress.org

Make WordPress Core

Changeset 45379


Ignore:
Timestamp:
05/23/2019 12:37:56 AM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r45378 r45379  
    26832683    global $wp_locale;
    26842684
    2685     $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
     2685    $post = get_post();
     2686
     2687    if ( ! $post ) {
     2688        return;
     2689    }
     2690
     2691    $the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
    26862692
    26872693    /**
     
    27032709 * @since 0.71
    27042710 *
    2705  * @global WP_Locale $wp_locale   The WordPress date and time locale object.
    2706  * @global string    $currentday  The day of the current post in the loop.
    2707  * @global string    $previousday The day of the previous post in the loop.
     2711 * @global WP_Locale $wp_locale       The WordPress date and time locale object.
     2712 * @global string    $currentday      The day of the current post in the loop.
     2713 * @global string    $previousweekday The day of the previous post in the loop.
    27082714 *
    27092715 * @param string $before Optional. Output before the date.
     
    27112717 */
    27122718function the_weekday_date( $before = '', $after = '' ) {
    2713     global $wp_locale, $currentday, $previousday;
     2719    global $wp_locale, $currentday, $previousweekday;
     2720
     2721    $post = get_post();
     2722
     2723    if ( ! $post ) {
     2724        return;
     2725    }
    27142726
    27152727    $the_weekday_date = '';
    27162728
    2717     if ( is_new_day() ) {
     2729    if ( $currentday !== $previousweekday ) {
    27182730        $the_weekday_date .= $before;
    2719         $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
     2731        $the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
    27202732        $the_weekday_date .= $after;
    2721         $previousday       = $currentday;
     2733        $previousweekday   = $currentday;
    27222734    }
    27232735
  • trunk/tests/phpunit/tests/date/theDate.php

    r45378 r45379  
    139139
    140140        ob_start();
    141         $GLOBALS['currentday']  = '18.09.15';
    142         $GLOBALS['previousday'] = '17.09.15';
     141        $GLOBALS['currentday']      = '18.09.15';
     142        $GLOBALS['previousweekday'] = '17.09.15';
    143143        the_weekday_date();
    144144        $this->assertEquals( 'Wednesday', ob_get_clean() );
    145145
    146146        ob_start();
    147         $GLOBALS['currentday']  = '18.09.15';
    148         $GLOBALS['previousday'] = '17.09.15';
     147        $GLOBALS['currentday']      = '18.09.15';
     148        $GLOBALS['previousweekday'] = '17.09.15';
    149149        the_weekday_date( 'before ', ' after' );
    150150        $this->assertEquals( 'before Wednesday after', ob_get_clean() );
Note: See TracChangeset for help on using the changeset viewer.