Make WordPress Core


Ignore:
Timestamp:
05/22/2019 09:57:29 PM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r45377 r45378  
    23412341    global $currentday, $previousday;
    23422342
     2343    $the_date = '';
     2344
    23432345    if ( is_new_day() ) {
    23442346        $the_date    = $before . get_the_date( $d ) . $after;
    23452347        $previousday = $currentday;
    2346 
    2347         /**
    2348          * Filters the date a post was published for display.
    2349          *
    2350          * @since 0.71
    2351          *
    2352          * @param string $the_date The formatted date string.
    2353          * @param string $d        PHP date format. Defaults to 'date_format' option
    2354          *                         if not specified.
    2355          * @param string $before   HTML output before the date.
    2356          * @param string $after    HTML output after the date.
    2357          */
    2358         $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
    2359 
    2360         if ( $echo ) {
    2361             echo $the_date;
    2362         } else {
    2363             return $the_date;
    2364         }
     2348    }
     2349
     2350    /**
     2351     * Filters the date a post was published for display.
     2352     *
     2353     * @since 0.71
     2354     *
     2355     * @param string $the_date The formatted date string.
     2356     * @param string $d        PHP date format. Defaults to 'date_format' option
     2357     *                         if not specified.
     2358     * @param string $before   HTML output before the date.
     2359     * @param string $after    HTML output after the date.
     2360     */
     2361    $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
     2362
     2363    if ( $echo ) {
     2364        echo $the_date;
     2365    } else {
     2366        return $the_date;
    23652367    }
    23662368}
     
    27012703 * @since 0.71
    27022704 *
    2703  * @global WP_Locale $wp_locale       The WordPress date and time locale object.
    2704  * @global string    $currentday      The day of the current post in the loop.
    2705  * @global string    $previousweekday The day of the previous post in the loop.
     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.
    27062708 *
    27072709 * @param string $before Optional. Output before the date.
     
    27092711 */
    27102712function the_weekday_date( $before = '', $after = '' ) {
    2711     global $wp_locale, $currentday, $previousweekday;
     2713    global $wp_locale, $currentday, $previousday;
     2714
    27122715    $the_weekday_date = '';
    2713     if ( $currentday != $previousweekday ) {
     2716
     2717    if ( is_new_day() ) {
    27142718        $the_weekday_date .= $before;
    27152719        $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
    27162720        $the_weekday_date .= $after;
    2717         $previousweekday   = $currentday;
     2721        $previousday       = $currentday;
    27182722    }
    27192723
     
    27272731     * @param string $after            The HTML to output after the date.
    27282732     */
    2729     $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
    2730     echo $the_weekday_date;
     2733    echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
    27312734}
    27322735
Note: See TracChangeset for help on using the changeset viewer.