diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index e7d4496b88..db06072c4a 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -449,6 +449,13 @@ window.wp = window.wp || {}; }; fields = $('#edit-'+id).find(':input').serialize(); + + var status = $(':input[name="_status"]').val(); + + if ( [ 'draft', 'pending', 'auto-draft' ].includes( status ) ) { + params.edit_date = 'false'; + } + params = fields + '&' + $.param(params); // Make Ajax request. diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 70f792f5f1..4036b2bbce 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -169,6 +169,10 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { } } + if ( isset( $post_data['edit_date'] ) && 'false' === $post_data['edit_date'] ) { + $post_data['edit_date'] = false; + } + if ( ! empty( $post_data['edit_date'] ) ) { $aa = $post_data['aa']; $mm = $post_data['mm']; diff --git a/tests/phpunit/tests/ajax/wpAjaxInlineSave.php b/tests/phpunit/tests/ajax/wpAjaxInlineSave.php index ad03e8eb00..3537def1dc 100644 --- a/tests/phpunit/tests/ajax/wpAjaxInlineSave.php +++ b/tests/phpunit/tests/ajax/wpAjaxInlineSave.php @@ -87,4 +87,59 @@ class Tests_Ajax_wpAjaxInlineSave extends WP_Ajax_UnitTestCase { $post_terms_2 = wp_get_object_terms( $post->ID, 'wptests_tax_2' ); $this->assertSameSets( array( $t2 ), wp_list_pluck( $post_terms_2, 'term_id' ) ); } + + /** + * When updating a draft in quick edit mode, it should not set the publish date of the post when this one will be published. + * + * @ticket 19907 + * + * @covers ::edit_post + */ + public function test_quick_edit_draft_should_not_set_publish_date() { + // Become an administrator. + $this->_setRole( 'administrator' ); + + $user = get_current_user_id(); + + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'draft', + 'post_author' => $user, + ) + ); + + $this->assertSame( 'draft', $post->post_status ); + + $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); + + // Set up a request. + $_POST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' ); + $_POST['post_ID'] = $post->ID; + $_POST['post_type'] = 'post'; + $_POST['content'] = 'content test'; + $_POST['excerpt'] = 'excerpt test'; + $_POST['_status'] = $post->post_status; + $_POST['post_status'] = $post->post_status; + $_POST['post_author'] = $user; + $_POST['screen'] = 'edit-post'; + $_POST['post_view'] = 'list'; + $_POST['edit_date'] = 'false'; + $_POST['mm'] = '09'; + $_POST['jj'] = 11; + $_POST['aa'] = 2020; + $_POST['hh'] = 19; + $_POST['mn'] = 20; + $_POST['ss'] = 11; + + // Make the request. + try { + $this->_handleAjax( 'inline-save' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + $post = get_post( $post->ID ); + + $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); + } }