Make WordPress Core

Ticket #39259: 39259.2.diff

File 39259.2.diff, 3.4 KB (added by dlh, 8 years ago)
  • src/wp-includes/theme.php

     
    16521652
    16531653                if ( $post_id > 0 && get_post( $post_id ) ) {
    16541654                        $post = get_post( $post_id );
    1655                 } else {
     1655                }
     1656
     1657                // `-1` indicates no post exists; no query necessary.
     1658                if ( ! $post && ( -1 !== $post_id ) ) {
    16561659                        $query = new WP_Query( $custom_css_query_vars );
    16571660                        $post = $query->post;
    16581661                        /*
     
    16591662                         * Cache the lookup. See WP_Customize_Custom_CSS_Setting::update().
    16601663                         * @todo This should get cleared if a custom_css post is added/removed.
    16611664                         */
    1662                         if ( $post ) {
    1663                                 set_theme_mod( 'custom_css_post_id', $post->ID );
    1664                         } elseif ( -1 !== $post_id ) {
    1665                                 set_theme_mod( 'custom_css_post_id', -1 );
    1666                         }
     1665                        set_theme_mod( 'custom_css_post_id', ( $post ) ? $post->ID : -1 );
    16671666                }
    16681667        } else {
    16691668                $query = new WP_Query( $custom_css_query_vars );
     
    17871786        } else {
    17881787                $r = wp_insert_post( wp_slash( $post_data ), true );
    17891788
    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 );
     1789                if ( ! is_wp_error( $r ) ) {
     1790                        if ( get_stylesheet() === $args['stylesheet'] ) {
     1791                                set_theme_mod( 'custom_css_post_id', $r );
     1792                        }
     1793
     1794                        // Trigger creation of a revision. This should be removed once #30854 is resolved.
     1795                        if ( 0 === count( wp_get_post_revisions( $r ) ) ) {
     1796                                wp_save_post_revision( $r );
     1797                        }
    17931798                }
    17941799        }
    17951800
  • tests/phpunit/tests/customize/custom-css-setting.php

     
    135135                ) );
    136136                $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' );
    137137
     138                remove_theme_mod( 'custom_css_post_id' );
     139
    138140                $this->assertEquals( $post_id, wp_get_custom_css_post()->ID );
    139141                $this->assertEquals( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID );
    140142                $this->assertEquals( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID );
     
    221223        }
    222224
    223225        /**
     226         * Test that wp_get_custom_css_post() doesn't query for a post after caching a failed lookup.
     227         *
     228         * @ticket 39258
     229         */
     230        function test_get_custom_css_post_queries_after_failed_lookup() {
     231                set_theme_mod( 'custom_css_post_id', -1 );
     232                $queries_before = get_num_queries();
     233                wp_get_custom_css_post();
     234                $this->assertSame( get_num_queries(), $queries_before );
     235        }
     236
     237        /**
     238         * Test that wp_update_custom_css_post() updates the 'custom_css_post_id' theme mod.
     239         *
     240         * @ticket 39258
     241         */
     242        function test_update_custom_css_updates_theme_mod() {
     243                set_theme_mod( 'custom_css_post_id', -1 );
     244                $post = wp_update_custom_css_post( 'body { background: blue; }' );
     245                $this->assertSame( $post->ID, get_theme_mod( 'custom_css_post_id' ) );
     246        }
     247
     248        /**
    224249         * Test crud methods on WP_Customize_Custom_CSS_Setting.
    225250         *
    226251         * @covers WP_Customize_Custom_CSS_Setting::value()
     
    237262                        'post_status' => 'publish',
    238263                        'post_type' => 'custom_css',
    239264                ) );
     265                remove_theme_mod( 'custom_css_post_id' );
    240266                $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() );
    241267
    242268                $this->wp_customize->set_post_value( $this->setting->id, '/*overridden*/' );