Make WordPress Core

Ticket #30854: 30854.3.diff

File 30854.3.diff, 6.9 KB (added by Mista-Flo, 2 years ago)

Clean

  • src/wp-includes/default-filters.php

    diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
    index e8e0a84d45..a606d52bdf 100644
    a b add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); 
    380380add_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
    381381// Create a revision whenever a post is updated.
    382382add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
     383add_action( 'new_to_publish', 'wp_save_post_revision', 10, 1 );
    383384add_action( 'publish_post', '_publish_post_hook', 5, 1 );
    384385add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
    385386add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 );
  • src/wp-includes/theme.php

    diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php
    index 916c836f43..7b478bc0ae 100644
    a b function wp_update_custom_css_post( $css, $args = array() ) { 
    20022002        } else {
    20032003                $r = wp_insert_post( wp_slash( $post_data ), true );
    20042004
    2005                 if ( ! is_wp_error( $r ) ) {
    2006                         if ( get_stylesheet() === $args['stylesheet'] ) {
    2007                                 set_theme_mod( 'custom_css_post_id', $r );
    2008                         }
    2009 
    2010                         // Trigger creation of a revision. This should be removed once #30854 is resolved.
    2011                         if ( 0 === count( wp_get_post_revisions( $r ) ) ) {
    2012                                 wp_save_post_revision( $r );
    2013                         }
     2005                if ( ! is_wp_error( $r ) && get_stylesheet() === $args['stylesheet'] ) {
     2006                        set_theme_mod( 'custom_css_post_id', $r );
    20142007                }
    20152008        }
    20162009
  • tests/phpunit/tests/post/revisions.php

    diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php
    index 95efe83578..0d05bad182 100644
    a b class Tests_Post_Revisions extends WP_UnitTestCase { 
    234234                );
    235235
    236236                $revisions = wp_get_post_revisions( $post_id );
    237                 $this->assertCount( 1, $revisions );
     237                $this->assertCount( 2, $revisions );
    238238                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    239239
    240240                foreach ( $revisions as $revision ) {
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    267267                );
    268268
    269269                $revisions = wp_get_post_revisions( $post_id );
    270                 $this->assertCount( 1, $revisions );
     270                $this->assertCount( 2, $revisions );
    271271                foreach ( $revisions as $revision ) {
    272272                        $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    273273                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    305305
    306306                // Diff checks if you can read both left and right revisions.
    307307                $revisions = wp_get_post_revisions( $post_id );
    308                 $this->assertCount( 2, $revisions );
     308                $this->assertCount( 3, $revisions );
    309309                foreach ( $revisions as $revision ) {
    310310                        $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) );
    311311                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    345345                );
    346346
    347347                $revisions = wp_get_post_revisions( $post_id );
    348                 $this->assertCount( 1, $revisions );
     348                $this->assertCount( 2, $revisions );
    349349                $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) );
    350350
    351351                foreach ( $revisions as $revision ) {
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    392392                );
    393393
    394394                $revisions = wp_get_post_revisions( $post_id );
    395                 $this->assertCount( 1, $revisions );
     395                $this->assertCount( 2, $revisions );
    396396                foreach ( $revisions as $revision ) {
    397397                        $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) );
    398398                }
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    456456                );
    457457
    458458                $revisions = wp_get_post_revisions( $post_id );
    459                 $this->assertCount( 2, $revisions );
     459                $this->assertCount( 3, $revisions );
    460460                foreach ( $revisions as $revision ) {
    461461                        $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) );
    462462                        $this->assertFalse( current_user_can( 'edit_post', $revision->ID ) );
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    517517        function test_wp_get_post_revisions_should_order_by_post_date() {
    518518                global $wpdb;
    519519
     520                $now  = time();
     521                $date = date( 'Y-m-d H:i:s', $now );
    520522                $post = self::factory()->post->create_and_get(
    521523                        array(
    522                                 'post_title'   => 'some-post',
    523                                 'post_type'    => 'post',
    524                                 'post_content' => 'some_content',
     524                                'post_title'    => 'some-post',
     525                                'post_type'     => 'post',
     526                                'post_content'  => 'some_content',
     527                                'post_date'     => $date,
     528                                'post_date_gmt' => $date
    525529                        )
    526530                );
    527531
    528532                $post                 = (array) $post;
     533                $revision_ids         = array();
     534                $revisions            = wp_get_post_revisions( $post['ID'] );
     535                $revision_ids[]       = current( $revisions )->ID;
    529536                $post_revision_fields = _wp_post_revision_data( $post );
    530537                $post_revision_fields = wp_slash( $post_revision_fields );
    531538
    532                 $revision_ids = array();
    533                 $now          = time();
    534539                for ( $j = 1; $j < 3; $j++ ) {
    535540                        // Manually modify dates to ensure they're different.
    536541                        $date                                  = gmdate( 'Y-m-d H:i:s', $now - ( $j * 10 ) );
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    551556         * @ticket 26042
    552557         */
    553558        function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() {
    554                 $post = self::factory()->post->create_and_get(
     559                $revision_ids = array();
     560                $date         = date( 'Y-m-d H:i:s', time() - 10 );
     561                $post         = self::factory()->post->create_and_get(
    555562                        array(
    556                                 'post_title'   => 'some-post',
    557                                 'post_type'    => 'post',
    558                                 'post_content' => 'some_content',
     563                                'post_title'    => 'some-post',
     564                                'post_type'     => 'post',
     565                                'post_content'  => 'some_content',
     566                                'post_date'     => $date,
     567                                'post_date_gmt' => $date
    559568                        )
    560569                );
    561570
    562571                $post                 = (array) $post;
    563572                $post_revision_fields = _wp_post_revision_data( $post );
    564573                $post_revision_fields = wp_slash( $post_revision_fields );
     574                $revisions = wp_get_post_revisions( $post['ID'] );
     575                $revision_ids[] = current( $revisions )->ID;
    565576
    566                 $revision_ids = array();
    567                 $date         = gmdate( 'Y-m-d H:i:s', time() - 10 );
    568577                for ( $j = 1; $j < 3; $j++ ) {
    569578                        // Manually modify dates to ensure they're the same.
    570579                        $post_revision_fields['post_date']     = $date;
    class Tests_Post_Revisions extends WP_UnitTestCase { 
    581590
    582591                $this->assertSame( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
    583592        }
     593
     594        /**
     595         * @ticket 30854
     596         */
     597        function test_wp_first_revision_is_not_lost() {
     598                $post = self::factory()->post->create_and_get( array(
     599                        'post_title' => 'some-post',
     600                        'post_type' => 'post',
     601                        'post_content' => 'Initial Content',
     602                ) );
     603
     604                wp_update_post( array(
     605                        'ID' => $post->ID,
     606                        'post_content' => 'Update #1',
     607                ) );
     608
     609                wp_update_post( array(
     610                        'ID' => $post->ID,
     611                        'post_content' => 'Update #2',
     612                ) );
     613
     614                $revisions = wp_get_post_revisions( $post->ID );
     615                $earliest_revision = end( $revisions );
     616
     617                $this->assertEquals( 'Initial Content', $earliest_revision->post_content );
     618        }
    584619}