diff --git src/wp-includes/post.php src/wp-includes/post.php
index 98ad57fbd0..b09795c382 100644
|
|
function wp_insert_post( $postarr, $wp_error = false ) { |
3451 | 3451 | $post_date_gmt = $postarr['post_date_gmt']; |
3452 | 3452 | } |
3453 | 3453 | |
3454 | | if ( $update || '0000-00-00 00:00:00' == $post_date ) { |
3455 | | $post_modified = current_time( 'mysql' ); |
3456 | | $post_modified_gmt = current_time( 'mysql', 1 ); |
| 3454 | // Set the post modified date. |
| 3455 | if ( empty( $postarr['post_modified'] ) || '0000-00-00 00:00:00' === $postarr['post_modified'] ) { |
| 3456 | if ( empty( $postarr['post_modified_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_modified_gmt'] ) { |
| 3457 | $post_modified = $update ? current_time( 'mysql' ) : $post_date; |
| 3458 | } else { |
| 3459 | $post_modified = get_date_from_gmt( $postarr['post_modified_gmt'] ); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | // Set the GMT version of the post modified date. |
| 3464 | if ( empty( $postarr['post_modified_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_modified_gmt'] ) { |
| 3465 | $post_modified_gmt = $update ? current_time( 'mysql', 1 ) : $post_date_gmt; |
3457 | 3466 | } else { |
3458 | | $post_modified = $post_date; |
3459 | | $post_modified_gmt = $post_date_gmt; |
| 3467 | $post_modified_gmt = $postarr['post_modified_gmt']; |
3460 | 3468 | } |
3461 | 3469 | |
3462 | 3470 | if ( 'attachment' !== $post_type ) { |
diff --git tests/phpunit/tests/post/wpInsertPost.php tests/phpunit/tests/post/wpInsertPost.php
index d459d9493d..f48fabf830 100644
|
|
class Tests_WPInsertPost extends WP_UnitTestCase { |
277 | 277 | $this->assertSame( $expected, $actual ); |
278 | 278 | } |
279 | 279 | |
| 280 | /** |
| 281 | * @ticket 41227 |
| 282 | */ |
| 283 | public function test_can_set_post_modified_fields_on_post_update() { |
| 284 | $date = new DateTime( '-2 hours', new DateTimeZone( 'UTC' ) ); |
| 285 | $post_id = self::factory()->post->create( array( |
| 286 | 'post_status' => 'publish', |
| 287 | 'post_date' => $date->format( 'Y-m-d H:i:s' ), |
| 288 | ) ); |
| 289 | |
| 290 | $date->modify( '+1 hour' ); |
| 291 | $modified_format = $date->format( 'Y-m-d H:i:s' ); |
| 292 | wp_update_post( array( |
| 293 | 'ID' => $post_id, |
| 294 | 'post_modified_gmt' => $modified_format, |
| 295 | ) ); |
| 296 | |
| 297 | $this->assertEquals( $modified_format, get_post( $post_id )->post_modified_gmt ); |
| 298 | } |
280 | 299 | } |