XML-RPC: Make sure editing a draft post with `wp.editPost` does not unintentionally cause its published date to be set.

Props redsweater.
Fixes #45322.

git-svn-id: https://develop.svn.wordpress.org/trunk@45906 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-08-29 02:09:42 +00:00
parent 5a1e3649c4
commit c3e89c2190
2 changed files with 39 additions and 0 deletions

View File

@ -1708,6 +1708,16 @@ class wp_xmlrpc_server extends IXR_Server {
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
}
/*
* If the API client did not provide post_date, then we must not perpetuate the value that was
* stored in the database, or it will appear to be an intentional edit. Conveying it here as if
* it was coming from the API client will cause an otherwise zeroed out post_date_gmt to get set
* with the value that was originally stored in the database when the draft was created.
*/
if ( ! isset( $content_struct['post_date'] ) ) {
unset( $post['post_date'] );
}
$this->escape( $post );
$merged_content_struct = array_merge( $post, $content_struct );

View File

@ -496,4 +496,33 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase {
$future_date_string = strftime( '%Y-%m-%d %H:%M:%S', $future_time );
$this->assertEquals( $future_date_string, $after->post_date );
}
/**
* @ticket 45322
*/
function test_draft_not_assigned_published_date() {
$editor_id = $this->make_user_by_role( 'editor' );
// Start with a draft post, confirming its post_date_gmt is "zero".
$post = array(
'post_title' => 'Test',
'post_status' => 'draft',
);
$post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
$before = get_post( $post_id );
$this->assertEquals( '0000-00-00 00:00:00', $before->post_date_gmt );
// Edit the post without specifying any dates.
$new_post_content = array(
'ID' => $post_id,
'post_title' => 'Updated',
);
$this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
// The published date should still be zero.
$after = get_post( $post_id );
$this->assertEquals( '0000-00-00 00:00:00', $after->post_date_gmt );
}
}