Make WordPress Core

Ticket #40657: trac-40657-reduce-timestamp.diff

File trac-40657-reduce-timestamp.diff, 9.2 KB (added by Rarst, 6 years ago)

Reduced explicit local current_time() timestamps use in core.

  • src/wp-admin/includes/ajax-actions.php

    diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
    index 04c31e51d3..9b523f6945 100644
    a b function wp_ajax_add_meta() { 
    13881388                        $post_data['post_ID']     = $pid;
    13891389                        $post_data['post_type']   = $post->post_type;
    13901390                        $post_data['post_status'] = 'draft';
    1391                         $now                      = current_time( 'timestamp', 1 );
     1391                        $now                      = time();
    13921392                        /* translators: 1: Post creation date, 2: Post creation time */
    13931393                        $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) );
    13941394
  • src/wp-admin/includes/dashboard.php

    diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
    index 0c5bb5f5b1..1d3dfb0ea5 100644
    a b function wp_dashboard_recent_posts( $args ) { 
    858858
    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() ) {
    865866                        $posts->the_post();
    function wp_dashboard_recent_posts( $args ) { 
    869870                                $relative = __( 'Today' );
    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 );
    875876                        } else {
  • src/wp-admin/includes/template.php

    diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php
    index 57dd7c2fcd..01af44bd8d 100644
    a b function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 
    762762        // todo: Remove this?
    763763        // 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 />';
    764764
    765         $time_adj  = current_time( 'timestamp' );
    766765        $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
    767         $jj        = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
    768         $mm        = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
    769         $aa        = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
    770         $hh        = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
    771         $mn        = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
    772         $ss        = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
    773 
    774         $cur_jj = gmdate( 'd', $time_adj );
    775         $cur_mm = gmdate( 'm', $time_adj );
    776         $cur_aa = gmdate( 'Y', $time_adj );
    777         $cur_hh = gmdate( 'H', $time_adj );
    778         $cur_mn = gmdate( 'i', $time_adj );
     766        $jj        = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
     767        $mm        = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
     768        $aa        = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
     769        $hh        = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
     770        $mn        = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
     771        $ss        = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
     772
     773        $cur_jj = current_time( 'd' );
     774        $cur_mm = current_time( 'm' );
     775        $cur_aa = current_time( 'Y' );
     776        $cur_hh = current_time( 'H' );
     777        $cur_mn = current_time( 'i' );
    779778
    780779        $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
    781780        for ( $i = 1; $i < 13; $i = $i + 1 ) {
  • src/wp-admin/includes/user.php

    diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php
    index fa868d913d..969c2c3f7d 100644
    a b protected function get_timestamp_as_date( $timestamp ) { 
    13151315                        return '';
    13161316                }
    13171317
    1318                 $time_diff = current_time( 'timestamp', true ) - $timestamp;
     1318                $time_diff = time() - $timestamp;
    13191319
    13201320                if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
    13211321                        /* translators: human readable timestamp */
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index d521a64eab..330c60e67c 100644
    a b function get_calendar( $initial = true, $echo = true ) { 
    19991999        }
    20002000        // week_begins = 0 stands for Sunday
    20012001        $week_begins = (int) get_option( 'start_of_week' );
    2002         $ts          = current_time( 'timestamp' );
    20032002
    20042003        // Let's figure out when we are
    20052004        if ( ! empty( $monthnum ) && ! empty( $year ) ) {
    function get_calendar( $initial = true, $echo = true ) { 
    20192018                        $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
    20202019                }
    20212020        } else {
    2022                 $thisyear  = gmdate( 'Y', $ts );
    2023                 $thismonth = gmdate( 'm', $ts );
     2021                $thisyear  = current_time( 'Y' );
     2022                $thismonth = current_time( 'm' );
    20242023        }
    20252024
    20262025        $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
    function get_calendar( $initial = true, $echo = true ) { 
    21292128                }
    21302129                $newrow = false;
    21312130
    2132                 if ( $day == gmdate( 'j', $ts ) &&
    2133                         $thismonth == gmdate( 'm', $ts ) &&
    2134                         $thisyear == gmdate( 'Y', $ts ) ) {
     2131                if ( $day == current_time( 'j' ) &&
     2132                        $thismonth == current_time( 'm' ) &&
     2133                        $thisyear == current_time( 'Y' ) ) {
    21352134                        $calendar_output .= '<td id="today">';
    21362135                } else {
    21372136                        $calendar_output .= '<td>';
  • src/wp-includes/link-template.php

    diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php
    index 815c539a4a..5a888b39e8 100644
    a b function get_attachment_link( $post = null, $leavename = false ) { 
    468468function get_year_link( $year ) {
    469469        global $wp_rewrite;
    470470        if ( ! $year ) {
    471                 $year = gmdate( 'Y', current_time( 'timestamp' ) );
     471                $year = current_time( 'Y' );
    472472        }
    473473        $yearlink = $wp_rewrite->get_year_permastruct();
    474474        if ( ! empty( $yearlink ) ) {
    function get_year_link( $year ) { 
    503503function get_month_link( $year, $month ) {
    504504        global $wp_rewrite;
    505505        if ( ! $year ) {
    506                 $year = gmdate( 'Y', current_time( 'timestamp' ) );
     506                $year = current_time( 'Y' );
    507507        }
    508508        if ( ! $month ) {
    509                 $month = gmdate( 'm', current_time( 'timestamp' ) );
     509                $month = current_time( 'm' );
    510510        }
    511511        $monthlink = $wp_rewrite->get_month_permastruct();
    512512        if ( ! empty( $monthlink ) ) {
    function get_month_link( $year, $month ) { 
    544544function get_day_link( $year, $month, $day ) {
    545545        global $wp_rewrite;
    546546        if ( ! $year ) {
    547                 $year = gmdate( 'Y', current_time( 'timestamp' ) );
     547                $year = current_time( 'Y' );
    548548        }
    549549        if ( ! $month ) {
    550                 $month = gmdate( 'm', current_time( 'timestamp' ) );
     550                $month = current_time( 'm' );
    551551        }
    552552        if ( ! $day ) {
    553                 $day = gmdate( 'j', current_time( 'timestamp' ) );
     553                $day = current_time( 'j' );
    554554        }
    555555
    556556        $daylink = $wp_rewrite->get_day_permastruct();
  • src/wp-includes/ms-functions.php

    diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php
    index f2dbbc750f..e205bf28ff 100644
    a b function wpmu_validate_user_signup( $user_name, $user_email ) { 
    518518        $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) );
    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.
    524524                if ( $diff > 2 * DAY_IN_SECONDS ) {
    function wpmu_validate_user_signup( $user_name, $user_email ) { 
    530530
    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 ) {
    536536                        $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) );
    function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { 
    688688        // Has someone already signed up for this domain?
    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 ) {
    694694                        $wpdb->delete(