diff --git src/wp-includes/post.php src/wp-includes/post.php
index 6360735..2f3aba9 100644
|
|
function wp_update_post( $postarr = array(), $wp_error = false ) { |
3538 | 3538 | $post_cats = $post['post_category']; |
3539 | 3539 | |
3540 | 3540 | // Drafts shouldn't be assigned a date unless explicitly done so by the user. |
| 3541 | $missing_date_fields = empty( $postarr['post_date'] ) && empty( $postarr['post_date_gmt'] ); |
3541 | 3542 | if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && |
3542 | | ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) |
| 3543 | ('0000-00-00 00:00:00' == $post['post_date_gmt']) && $missing_date_fields ) |
3543 | 3544 | $clear_date = true; |
3544 | 3545 | else |
3545 | 3546 | $clear_date = false; |
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index 4f5a294..636b82b 100644
|
|
class Tests_Post extends WP_UnitTestCase { |
1258 | 1258 | $this->assertEquals( 0, get_post( $page_id )->post_parent ); |
1259 | 1259 | } |
1260 | 1260 | |
| 1261 | /** |
| 1262 | * @ticket 35874 |
| 1263 | */ |
| 1264 | function test_wp_update_post_should_respect_post_date() { |
| 1265 | $post = array( |
| 1266 | 'post_author' => self::$editor_id, |
| 1267 | 'post_status' => 'draft', |
| 1268 | 'post_content' => rand_str(), |
| 1269 | 'post_title' => rand_str(), |
| 1270 | ); |
| 1271 | |
| 1272 | $id = wp_insert_post($post); |
| 1273 | |
| 1274 | $out = get_post($id); |
| 1275 | |
| 1276 | // Change the post status to publish while also supplying a date |
| 1277 | $specific_date = strftime("%Y-%m-%d %H:%M:%S", strtotime('+1 day')); |
| 1278 | |
| 1279 | $post['ID'] = $id; |
| 1280 | $post['post_date'] = $specific_date; |
| 1281 | $post['post_status'] = 'publish'; |
| 1282 | wp_update_post( $post ); |
| 1283 | |
| 1284 | // Updated post should still possess the specified date |
| 1285 | $out = get_post($id); |
| 1286 | $this->assertEquals($specific_date, $out->post_date); |
| 1287 | } |
| 1288 | |
1261 | 1289 | } |