Quick/Bulk Edit: Don't set publish date when editing drafts.

Ensure that quick edit does not define a publish date if the post status is one of 'draft', 'pending', or 'auto-draft'.

Props uxtremist, SergeyBiryukov, Denis-de-Bernardy, jane, rfischmann, mista-flo, rutviksavsani, oglekler, joedolson.
Fixes #19907.

git-svn-id: https://develop.svn.wordpress.org/trunk@56022 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson
2023-06-25 15:18:12 +00:00
parent 7a6bff44fc
commit ed54bb7444
3 changed files with 66 additions and 0 deletions

View File

@@ -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.

View File

@@ -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'];

View File

@@ -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 );
}
}