Make WordPress Core

Ticket #35874: fix-and-test-update-post-2.patch

File fix-and-test-update-post-2.patch, 1.8 KB (added by redsweater, 9 years ago)

Updated patch that attempts to address the bug more conservatively

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 6360735..2f3aba9 100644
    function wp_update_post( $postarr = array(), $wp_error = false ) { 
    35383538                $post_cats = $post['post_category'];
    35393539
    35403540        // Drafts shouldn't be assigned a date unless explicitly done so by the user.
     3541        $missing_date_fields = empty( $postarr['post_date'] ) && empty( $postarr['post_date_gmt'] );
    35413542        if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&
    3542                          ('0000-00-00 00:00:00' == $post['post_date_gmt']) )
     3543                         ('0000-00-00 00:00:00' == $post['post_date_gmt']) && $missing_date_fields )
    35433544                $clear_date = true;
    35443545        else
    35453546                $clear_date = false;
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index 4f5a294..636b82b 100644
    class Tests_Post extends WP_UnitTestCase { 
    12581258                $this->assertEquals( 0, get_post( $page_id )->post_parent );
    12591259        }
    12601260
     1261        /**
     1262         * @ticket 35874
     1263         */
     1264        function test_wp_update_post_should_respect_post_date() {
     1265                $post = array(
     1266                        'post_author' => self::$editor_id,
     1267                        'post_status' => 'draft',
     1268                        'post_content' => rand_str(),
     1269                        'post_title' => rand_str(),
     1270                );
     1271
     1272                $id = wp_insert_post($post);
     1273
     1274                $out = get_post($id);
     1275
     1276                // Change the post status to publish while also supplying a date
     1277                $specific_date = strftime("%Y-%m-%d %H:%M:%S", strtotime('+1 day'));
     1278
     1279                $post['ID'] = $id;
     1280                $post['post_date'] = $specific_date;
     1281                $post['post_status'] = 'publish';
     1282                wp_update_post( $post );
     1283
     1284                // Updated post should still possess the specified date
     1285                $out = get_post($id);
     1286                $this->assertEquals($specific_date, $out->post_date);
     1287        }
     1288
    12611289}