WordPress.org

Make WordPress Core

Changeset 45906


Ignore:
Timestamp:
08/29/2019 02:09:42 AM (3 weeks ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r45823 r45906  
    17091709        }
    17101710
     1711        /*
     1712         * If the API client did not provide post_date, then we must not perpetuate the value that was
     1713         * stored in the database, or it will appear to be an intentional edit. Conveying it here as if
     1714         * it was coming from the API client will cause an otherwise zeroed out post_date_gmt to get set
     1715         * with the value that was originally stored in the database when the draft was created.
     1716         */
     1717        if ( ! isset( $content_struct['post_date'] ) ) {
     1718            unset( $post['post_date'] );
     1719        }
     1720
    17111721        $this->escape( $post );
    17121722        $merged_content_struct = array_merge( $post, $content_struct );
  • trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php

    r45607 r45906  
    497497        $this->assertEquals( $future_date_string, $after->post_date );
    498498    }
     499
     500    /**
     501     * @ticket 45322
     502     */
     503    function test_draft_not_assigned_published_date() {
     504        $editor_id = $this->make_user_by_role( 'editor' );
     505
     506        // Start with a draft post, confirming its post_date_gmt is "zero".
     507        $post    = array(
     508            'post_title'  => 'Test',
     509            'post_status' => 'draft',
     510        );
     511        $post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     512
     513        $before  = get_post( $post_id );
     514        $this->assertEquals( '0000-00-00 00:00:00', $before->post_date_gmt );
     515
     516        // Edit the post without specifying any dates.
     517        $new_post_content = array(
     518            'ID'         => $post_id,
     519            'post_title' => 'Updated',
     520        );
     521
     522        $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
     523
     524        // The published date should still be zero.
     525        $after = get_post( $post_id );
     526        $this->assertEquals( '0000-00-00 00:00:00', $after->post_date_gmt );
     527    }
    499528}
Note: See TracChangeset for help on using the changeset viewer.