Make WordPress Core


Ignore:
Timestamp:
05/26/2019 12:11:37 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Replace all instances of date() with gmdate().

Use of date() in core depends on PHP timezone set to UTC and not changed by third party code (which cannot be guaranteed).

gmdate() is functionally equivalent, but is not affected by PHP timezone setting: it's always UTC, which is the exact behavior the core needs.

Props nielsdeblaauw, Rarst.
Fixes #46438. See #44491.

File:
1 edited

Legend:

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

    r45406 r45424  
    21082108
    21092109    $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
    2110     $last_day  = date( 't', $unixmonth );
     2110    $last_day  = gmdate( 't', $unixmonth );
    21112111
    21122112    // Get the next and previous month and year with at least one post
     
    21342134        $calendar_caption,
    21352135        $wp_locale->get_month( $thismonth ),
    2136         date( 'Y', $unixmonth )
     2136        gmdate( 'Y', $unixmonth )
    21372137    ) . '</caption>
    21382138    <thead>
     
    22002200
    22012201    // See how much we should pad in the beginning
    2202     $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins );
     2202    $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins );
    22032203    if ( 0 != $pad ) {
    22042204        $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad">&nbsp;</td>';
     
    22062206
    22072207    $newrow      = false;
    2208     $daysinmonth = (int) date( 't', $unixmonth );
     2208    $daysinmonth = (int) gmdate( 't', $unixmonth );
    22092209
    22102210    for ( $day = 1; $day <= $daysinmonth; ++$day ) {
     
    22242224        if ( in_array( $day, $daywithpost ) ) {
    22252225            // any posts today?
    2226             $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
     2226            $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
    22272227            /* translators: Post calendar label. %s: Date */
    22282228            $label            = sprintf( __( 'Posts published on %s' ), $date_format );
     
    22382238        $calendar_output .= '</td>';
    22392239
    2240         if ( 6 == calendar_week_mod( date( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
     2240        if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
    22412241            $newrow = true;
    22422242        }
    22432243    }
    22442244
    2245     $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
     2245    $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
    22462246    if ( $pad != 0 && $pad != 7 ) {
    22472247        $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">&nbsp;</td>';
     
    44534453            break;
    44544454        case 'export':
    4455             $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . date( 'Y-m-d H:i' ) . '" -->';
     4455            $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->';
    44564456            break;
    44574457    }
Note: See TracChangeset for help on using the changeset viewer.