diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 7636c3d02b..306e567bb9 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -3663,14 +3663,13 @@ function wp_insert_post( $postarr, $wp_error = false ) { } if ( 'attachment' !== $post_type ) { - if ( 'publish' == $post_status ) { - $now = gmdate( 'Y-m-d H:i:59' ); - if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) { + if ( 'publish' === $post_status ) { + // String comparison to work around far future dates (year 2038+) on 32-bit systems. + if ( $post_date_gmt > gmdate( 'Y-m-d H:i:59' ) ) { $post_status = 'future'; } - } elseif ( 'future' == $post_status ) { - $now = gmdate( 'Y-m-d H:i:59' ); - if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) { + } elseif ( 'future' === $post_status ) { + if ( $post_date_gmt <= gmdate( 'Y-m-d H:i:59' ) ) { $post_status = 'publish'; } } diff --git a/tests/phpunit/tests/post/wpInsertPost.php b/tests/phpunit/tests/post/wpInsertPost.php index 519248a567..b52ba74c03 100644 --- a/tests/phpunit/tests/post/wpInsertPost.php +++ b/tests/phpunit/tests/post/wpInsertPost.php @@ -302,4 +302,25 @@ class Tests_WPInsertPost extends WP_UnitTestCase { $this->assertSame( $expected, $actual ); } + /** + * @ticket 25347 + */ + function test_scheduled_post_with_a_past_date_should_be_published() { + + $now = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) ); + + $post_id = $this->factory()->post->create( [ + 'post_date_gmt' => $now->modify( '-1 year' )->format( 'Y-m-d H:i:s' ), + 'post_status' => 'future', + ] ); + + $this->assertEquals( 'publish', get_post_status( $post_id ) ); + + $post_id = $this->factory()->post->create( [ + 'post_date_gmt' => $now->modify( '+50 years' )->format( 'Y-m-d H:i:s' ), + 'post_status' => 'future', + ] ); + + $this->assertEquals( 'future', get_post_status( $post_id ) ); + } }