WordPress.org

Make WordPress Core

Changeset 44809


Ignore:
Timestamp:
03/07/2019 09:11:37 AM (21 months ago)
Author:
SergeyBiryukov
Message:

Date/Time: Reduce explicit local current_time( 'timestamp' ) usage in favor of native PHP functions.

Timestamps don't carry any timezone information, using the intended format directly simplifies the logic and makes the code less confusing.

Props Rarst, jdgrimes.
See #40657.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r44785 r44809  
    14651465            $post_data['post_type']   = $post->post_type;
    14661466            $post_data['post_status'] = 'draft';
    1467             $now                      = current_time( 'timestamp', 1 );
     1467            $now                      = time();
    14681468            /* translators: 1: Post creation date, 2: Post creation time */
    14691469            $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) );
  • trunk/src/wp-admin/includes/dashboard.php

    r44759 r44809  
    859859        echo '<ul>';
    860860
    861         $today    = date( 'Y-m-d', current_time( 'timestamp' ) );
    862         $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
     861        $today    = current_time( 'Y-m-d' );
     862        $tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
     863        $year     = current_time( 'Y' );
    863864
    864865        while ( $posts->have_posts() ) {
     
    870871            } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
    871872                $relative = __( 'Tomorrow' );
    872             } elseif ( date( 'Y', $time ) !== date( 'Y', current_time( 'timestamp' ) ) ) {
     873            } elseif ( date( 'Y', $time ) !== $year ) {
    873874                /* translators: date and time format for recent posts on the dashboard, from a different calendar year, see https://secure.php.net/date */
    874875                $relative = date_i18n( __( 'M jS Y' ), $time );
  • trunk/src/wp-admin/includes/template.php

    r44759 r44809  
    775775    // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
    776776
    777     $time_adj  = current_time( 'timestamp' );
    778777    $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
    779     $jj        = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
    780     $mm        = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
    781     $aa        = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
    782     $hh        = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
    783     $mn        = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
    784     $ss        = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
    785 
    786     $cur_jj = gmdate( 'd', $time_adj );
    787     $cur_mm = gmdate( 'm', $time_adj );
    788     $cur_aa = gmdate( 'Y', $time_adj );
    789     $cur_hh = gmdate( 'H', $time_adj );
    790     $cur_mn = gmdate( 'i', $time_adj );
     778    $jj        = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
     779    $mm        = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
     780    $aa        = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
     781    $hh        = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
     782    $mn        = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
     783    $ss        = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
     784
     785    $cur_jj = current_time( 'd' );
     786    $cur_mm = current_time( 'm' );
     787    $cur_aa = current_time( 'Y' );
     788    $cur_hh = current_time( 'H' );
     789    $cur_mn = current_time( 'i' );
    791790
    792791    $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
  • trunk/src/wp-admin/includes/user.php

    r44775 r44809  
    13931393        }
    13941394
    1395         $time_diff = current_time( 'timestamp', true ) - $timestamp;
     1395        $time_diff = time() - $timestamp;
    13961396
    13971397        if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
  • trunk/src/wp-includes/general-template.php

    r44725 r44809  
    20062006    // week_begins = 0 stands for Sunday
    20072007    $week_begins = (int) get_option( 'start_of_week' );
    2008     $ts          = current_time( 'timestamp' );
    20092008
    20102009    // Let's figure out when we are
     
    20262025        }
    20272026    } else {
    2028         $thisyear  = gmdate( 'Y', $ts );
    2029         $thismonth = gmdate( 'm', $ts );
     2027        $thisyear  = current_time( 'Y' );
     2028        $thismonth = current_time( 'm' );
    20302029    }
    20312030
     
    21372136        $newrow = false;
    21382137
    2139         if ( $day == gmdate( 'j', $ts ) &&
    2140             $thismonth == gmdate( 'm', $ts ) &&
    2141             $thisyear == gmdate( 'Y', $ts ) ) {
     2138        if ( $day == current_time( 'j' ) &&
     2139            $thismonth == current_time( 'm' ) &&
     2140            $thisyear == current_time( 'Y' ) ) {
    21422141            $calendar_output .= '<td id="today">';
    21432142        } else {
  • trunk/src/wp-includes/link-template.php

    r44591 r44809  
    471471    global $wp_rewrite;
    472472    if ( ! $year ) {
    473         $year = gmdate( 'Y', current_time( 'timestamp' ) );
     473        $year = current_time( 'Y' );
    474474    }
    475475    $yearlink = $wp_rewrite->get_year_permastruct();
     
    506506    global $wp_rewrite;
    507507    if ( ! $year ) {
    508         $year = gmdate( 'Y', current_time( 'timestamp' ) );
     508        $year = current_time( 'Y' );
    509509    }
    510510    if ( ! $month ) {
    511         $month = gmdate( 'm', current_time( 'timestamp' ) );
     511        $month = current_time( 'm' );
    512512    }
    513513    $monthlink = $wp_rewrite->get_month_permastruct();
     
    547547    global $wp_rewrite;
    548548    if ( ! $year ) {
    549         $year = gmdate( 'Y', current_time( 'timestamp' ) );
     549        $year = current_time( 'Y' );
    550550    }
    551551    if ( ! $month ) {
    552         $month = gmdate( 'm', current_time( 'timestamp' ) );
     552        $month = current_time( 'm' );
    553553    }
    554554    if ( ! $day ) {
    555         $day = gmdate( 'j', current_time( 'timestamp' ) );
     555        $day = current_time( 'j' );
    556556    }
    557557
  • trunk/src/wp-includes/ms-functions.php

    r44469 r44809  
    519519    if ( $signup != null ) {
    520520        $registered_at = mysql2date( 'U', $signup->registered );
    521         $now           = current_time( 'timestamp', true );
     521        $now           = time();
    522522        $diff          = $now - $registered_at;
    523523        // If registered more than two days ago, cancel registration and let this signup go through.
     
    531531    $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) );
    532532    if ( $signup != null ) {
    533         $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered );
     533        $diff = time() - mysql2date( 'U', $signup->registered );
    534534        // If registered more than two days ago, cancel registration and let this signup go through.
    535535        if ( $diff > 2 * DAY_IN_SECONDS ) {
     
    689689    $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); // TODO: Check email too?
    690690    if ( ! empty( $signup ) ) {
    691         $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered );
     691        $diff = time() - mysql2date( 'U', $signup->registered );
    692692        // If registered more than two days ago, cancel registration and let this signup go through.
    693693        if ( $diff > 2 * DAY_IN_SECONDS ) {
Note: See TracChangeset for help on using the changeset viewer.