Make WordPress Core

Ticket #30854: 30854.9.diff

File 30854.9.diff, 6.1 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..39ce7380b8 100644
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    229229                );
    230230
    231231                $revisions = wp_get_post_revisions( $post_id );
    232                 $this->assertCount( 1, $revisions );
     232                $this->assertCount( 2, $revisions );
    233233                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    234234
    235235                foreach ( $revisions as $revision ) {
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    262262                );
    263263
    264264                $revisions = wp_get_post_revisions( $post_id );
    265                 $this->assertCount( 1, $revisions );
     265                $this->assertCount( 2, $revisions );
    266266                foreach ( $revisions as $revision ) {
    267267                        $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    268268                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    300300
    301301                // Diff checks if you can read both left and right revisions.
    302302                $revisions = wp_get_post_revisions( $post_id );
    303                 $this->assertCount( 2, $revisions );
     303                $this->assertCount( 3, $revisions );
    304304                foreach ( $revisions as $revision ) {
    305305                        $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) );
    306306                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    340340                );
    341341
    342342                $revisions = wp_get_post_revisions( $post_id );
    343                 $this->assertCount( 1, $revisions );
     343                $this->assertCount( 2, $revisions );
    344344                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    345345
    346346                foreach ( $revisions as $revision ) {
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    387387                );
    388388
    389389                $revisions = wp_get_post_revisions( $post_id );
    390                 $this->assertCount( 1, $revisions );
     390                $this->assertCount( 2, $revisions );
    391391                foreach ( $revisions as $revision ) {
    392392                        $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    393393                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    495495
    496496                // Diff checks if you can read both left and right revisions.
    497497                $revisions = wp_get_post_revisions( $post_id );
    498                 $this->assertCount( 2, $revisions );
     498                $this->assertCount( 3, $revisions );
    499499                foreach ( $revisions as $revision ) {
    500500                        $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) );
    501501                }
    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..6f4c80f74c 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(
    class Tests_XMLRPC_wp_getRevisions extends WP_XMLRPC_UnitTestCase { 
    5353
    5454                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
    5555                $this->assertIsArray( $result );
    56                 $this->assertCount( 2, $result );
     56                $this->assertCount( 3, $result );
    5757        }
    5858
    5959        /**