Make WordPress Core

Changeset 39477


Ignore:
Timestamp:
12/04/2016 05:28:27 PM (7 years ago)
Author:
westonruter
Message:

Customize: Ensure a custom_css post insertion gets an initial post revision.

Props georgestephanis, westonruter.
See #30854, #38672, #35395.
Fixes #39032.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r39350 r39477  
    17871787    } else {
    17881788        $r = wp_insert_post( wp_slash( $post_data ), true );
    1789     }
    1790 
    1791     if ( $r instanceof WP_Error ) {
     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        }
     1794    }
     1795
     1796    if ( is_wp_error( $r ) ) {
    17921797        return $r;
    17931798    }
  • trunk/tests/phpunit/tests/customize/custom-css-setting.php

    r39350 r39477  
    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     *
Note: See TracChangeset for help on using the changeset viewer.