diff --git src/wp-includes/class-wp-xmlrpc-server.php src/wp-includes/class-wp-xmlrpc-server.php
index c331591..c21afb6 100644
|
|
class wp_xmlrpc_server extends IXR_Server { |
5362 | 5362 | elseif ( !empty( $content_struct['dateCreated']) ) |
5363 | 5363 | $dateCreated = $content_struct['dateCreated']->getIso(); |
5364 | 5364 | |
| 5365 | // We need to pass along a value to wp_update_post for "edit_date", indicating whether |
| 5366 | // an intentional edit is being made to the date. This drives logic that determines |
| 5367 | // whether the value of post_date or post_date_gmt will be disregarded or not for |
| 5368 | // draft posts. |
| 5369 | $edit_date = false; |
5365 | 5370 | if ( !empty( $dateCreated ) ) { |
5366 | 5371 | $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
5367 | 5372 | $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
| 5373 | |
| 5374 | // If $dateCreated is not empty, it means that a specific date was supplied. |
| 5375 | $edit_date = true; |
5368 | 5376 | } else { |
5369 | 5377 | $post_date = $postdata['post_date']; |
5370 | 5378 | $post_date_gmt = $postdata['post_date_gmt']; |
5371 | 5379 | } |
5372 | 5380 | |
5373 | 5381 | // We've got all the data -- post it. |
5374 | | $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template'); |
| 5382 | $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template'); |
5375 | 5383 | |
5376 | 5384 | $result = wp_update_post($newpost, true); |
5377 | 5385 | if ( is_wp_error( $result ) ) |
diff --git tests/phpunit/tests/xmlrpc/mw/editPost.php tests/phpunit/tests/xmlrpc/mw/editPost.php
index a62d239..8c26522 100644
|
|
class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { |
241 | 241 | $tags2 = get_the_tags( $post_id ); |
242 | 242 | $this->assertEmpty( $tags2 ); |
243 | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * @ticket 35874 |
| 247 | */ |
| 248 | function test_draft_not_prematurely_published() { |
| 249 | $editor_id = $this->make_user_by_role( 'editor' ); |
| 250 | |
| 251 | $post = array ( |
| 252 | 'title' => 'Title' |
| 253 | ); |
| 254 | |
| 255 | // We have to use mw_newPost method, rather than the factory |
| 256 | // post->create method to create the database conditions that exhibit the bug. |
| 257 | $post_id = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); |
| 258 | |
| 259 | // Change the post's status to publish and date to future |
| 260 | $future_time = strtotime( '+1 day' ); |
| 261 | $future_date = new IXR_Date( $future_time ); |
| 262 | $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array( |
| 263 | 'dateCreated' => $future_date, |
| 264 | 'post_status' => 'publish' |
| 265 | ) ) ); |
| 266 | |
| 267 | $after = get_post( $post_id ); |
| 268 | $this->assertEquals( 'future', $after->post_status ); |
| 269 | |
| 270 | $future_date_string = strftime( "%Y-%m-%d %H:%M:%S", $future_time ); |
| 271 | $this->assertEquals( $future_date_string, $after->post_date ); |
| 272 | } |
244 | 273 | } |