WordPress.org

Make WordPress Core

Ticket #39032: 39032.5.diff

File 39032.5.diff, 2.0 KB (added by westonruter, 5 years ago)
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index cf1bb0f..8aac86c 100644
    function wp_update_custom_css_post( $css, $args = array() ) { 
    17861786                $r = wp_update_post( wp_slash( $post_data ), true );
    17871787        } else {
    17881788                $r = wp_insert_post( wp_slash( $post_data ), true );
     1789
     1790                // Trigger creation of a revision. This should be removed once #30854 is resolved.
     1791                if ( ! is_wp_error( $r ) && 0 === count( wp_get_post_revisions( $r ) ) ) {
     1792                        wp_save_post_revision( $r );
     1793                }
    17891794        }
    17901795
    1791         if ( $r instanceof WP_Error ) {
     1796        if ( is_wp_error( $r ) ) {
    17921797                return $r;
    17931798        }
    17941799        return get_post( $r );
  • tests/phpunit/tests/customize/custom-css-setting.php

    diff --git tests/phpunit/tests/customize/custom-css-setting.php tests/phpunit/tests/customize/custom-css-setting.php
    index e787094..102d303 100644
    class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase { 
    193193        }
    194194
    195195        /**
     196         * Test revision saving on initial save of Custom CSS.
     197         *
     198         * @ticket 39032
     199         */
     200        function test_custom_css_revision_saved() {
     201                $inserted_css = 'body { background: black; }';
     202                $updated_css = 'body { background: red; }';
     203
     204                $post = wp_update_custom_css_post( $inserted_css, array(
     205                        'stylesheet' => 'testtheme',
     206                ) );
     207
     208                $this->assertSame( $inserted_css, $post->post_content );
     209                $revisions = array_values( wp_get_post_revisions( $post ) );
     210                $this->assertCount( 1, $revisions );
     211                $this->assertSame( $inserted_css, $revisions[0]->post_content );
     212
     213                wp_update_custom_css_post( $updated_css, array(
     214                        'stylesheet' => 'testtheme',
     215                ) );
     216
     217                $revisions = array_values( wp_get_post_revisions( $post ) );
     218                $this->assertCount( 2, $revisions );
     219                $this->assertSame( $updated_css, $revisions[0]->post_content );
     220                $this->assertSame( $inserted_css, $revisions[1]->post_content );
     221        }
     222
     223        /**
    196224         * Test crud methods on WP_Customize_Custom_CSS_Setting.
    197225         *
    198226         * @covers WP_Customize_Custom_CSS_Setting::value()