Make WordPress Core

Ticket #30854: 30854.8.diff

File 30854.8.diff, 3.7 KB (added by adamsilverstein, 4 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index a446eed1c2..9c65467080 100644
    add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); 
    401401add_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
    402402// Create a revision whenever a post is updated.
    403403add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
     404// Fired in `wp_transition_post_status` for newly created posts with status 'publish'.
     405add_action( 'new_to_publish', 'wp_save_post_revision', 10, 1 );
    404406add_action( 'publish_post', '_publish_post_hook', 5, 1 );
    405407add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
    406408add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 );
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index a7bc431c37..1770e6cb52 100644
    function wp_update_custom_css_post( $css, $args = array() ) { 
    20172017        } else {
    20182018                $r = wp_insert_post( wp_slash( $post_data ), true );
    20192019
    2020                 if ( ! is_wp_error( $r ) ) {
    2021                         if ( get_stylesheet() === $args['stylesheet'] ) {
    2022                                 set_theme_mod( 'custom_css_post_id', $r );
    2023                         }
    2024 
    2025                         // Trigger creation of a revision. This should be removed once #30854 is resolved.
    2026                         if ( 0 === count( wp_get_post_revisions( $r ) ) ) {
    2027                                 wp_save_post_revision( $r );
    2028                         }
     2020                if ( ! is_wp_error( $r ) && get_stylesheet() === $args['stylesheet'] ) {
     2021                        set_theme_mod( 'custom_css_post_id', $r );
    20292022                }
    20302023        }
    20312024
  • tests/phpunit/tests/post/revisions.php

    diff --git tests/phpunit/tests/post/revisions.php tests/phpunit/tests/post/revisions.php
    index 35e43f18ae..0cb0c6bffd 100644
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    539539
    540540                $revisions = wp_get_post_revisions( $post['ID'] );
    541541
     542                array_unshift( $revision_ids, reset( $revisions )->ID );
     543
    542544                $this->assertSame( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
    543545        }
    544546
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    574576
    575577                $revisions = wp_get_post_revisions( $post['ID'] );
    576578
     579                array_unshift( $revision_ids, reset( $revisions )->ID );
     580
    577581                $this->assertSame( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
    578582        }
    579583
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    654658
    655659                $this->assertWPError( $revision );
    656660        }
     661
     662        /**
     663         * @ticket 30854
     664         */
     665        function test_wp_first_revision_is_not_lost() {
     666                $post = self::factory()->post->create_and_get(
     667                        array(
     668                                'post_title'   => 'some-post',
     669                                'post_type'    => 'post',
     670                                'post_content' => 'Initial Content',
     671                        )
     672                );
     673
     674                wp_update_post(
     675                        array(
     676                                'ID'           => $post->ID,
     677                                'post_content' => 'Update #1',
     678                        )
     679                );
     680
     681                wp_update_post(
     682                        array(
     683                                'ID'           => $post->ID,
     684                                'post_content' => 'Update #2',
     685                        )
     686                );
     687
     688                $revisions         = wp_get_post_revisions( $post->ID );
     689                $earliest_revision = end( $revisions );
     690
     691                $this->assertEquals( 'Initial Content', $earliest_revision->post_content );
     692        }
    657693}
  • tests/phpunit/tests/xmlrpc/wp/getRevisions.php

    diff --git tests/phpunit/tests/xmlrpc/wp/getRevisions.php tests/phpunit/tests/xmlrpc/wp/getRevisions.php
    index b7a4667165..03814bc7bf 100644
    class Tests_XMLRPC_wp_getRevisions extends WP_XMLRPC_UnitTestCase { 
    4242
    4343                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
    4444                $this->assertIsArray( $result );
    45                 $this->assertCount( 1, $result );
     45                $this->assertCount( 2, $result );
    4646
    4747                wp_insert_post(
    4848                        array(