WordPress.org

Make WordPress Core

Changeset 45851


Ignore:
Timestamp:
08/19/2019 03:49:32 PM (5 weeks ago)
Author:
SergeyBiryukov
Message:

Date/Time: In wp_insert_post(), when checking the post date to set future or publish status, use string comparison to work around far future dates (year 2038+) on 32-bit systems.

Props Rarst, nofearinc.
Fixes #25347.

Location:
trunk
Files:
2 edited

Legend:

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

    r45779 r45851  
    36643664
    36653665    if ( 'attachment' !== $post_type ) {
    3666         if ( 'publish' == $post_status ) {
    3667             $now = gmdate( 'Y-m-d H:i:59' );
    3668             if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) {
     3666        if ( 'publish' === $post_status ) {
     3667            // String comparison to work around far future dates (year 2038+) on 32-bit systems.
     3668            if ( $post_date_gmt > gmdate( 'Y-m-d H:i:59' ) ) {
    36693669                $post_status = 'future';
    36703670            }
    3671         } elseif ( 'future' == $post_status ) {
    3672             $now = gmdate( 'Y-m-d H:i:59' );
    3673             if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) {
     3671        } elseif ( 'future' === $post_status ) {
     3672            if ( $post_date_gmt <= gmdate( 'Y-m-d H:i:59' ) ) {
    36743673                $post_status = 'publish';
    36753674            }
  • trunk/tests/phpunit/tests/post/wpInsertPost.php

    r43571 r45851  
    303303    }
    304304
     305    /**
     306     * @ticket 25347
     307     */
     308    function test_scheduled_post_with_a_past_date_should_be_published() {
     309
     310        $now = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) );
     311
     312        $post_id = $this->factory()->post->create( [
     313            'post_date_gmt' => $now->modify( '-1 year' )->format( 'Y-m-d H:i:s' ),
     314            'post_status'   => 'future',
     315        ] );
     316
     317        $this->assertEquals( 'publish', get_post_status( $post_id ) );
     318
     319        $post_id = $this->factory()->post->create( [
     320            'post_date_gmt' => $now->modify( '+50 years' )->format( 'Y-m-d H:i:s' ),
     321            'post_status'   => 'future',
     322        ] );
     323
     324        $this->assertEquals( 'future', get_post_status( $post_id ) );
     325    }
    305326}
Note: See TracChangeset for help on using the changeset viewer.