Ticket #39259: 39259.2.diff
File 39259.2.diff, 3.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/theme.php
1652 1652 1653 1653 if ( $post_id > 0 && get_post( $post_id ) ) { 1654 1654 $post = get_post( $post_id ); 1655 } else { 1655 } 1656 1657 // `-1` indicates no post exists; no query necessary. 1658 if ( ! $post && ( -1 !== $post_id ) ) { 1656 1659 $query = new WP_Query( $custom_css_query_vars ); 1657 1660 $post = $query->post; 1658 1661 /* … … 1659 1662 * Cache the lookup. See WP_Customize_Custom_CSS_Setting::update(). 1660 1663 * @todo This should get cleared if a custom_css post is added/removed. 1661 1664 */ 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 ); 1667 1666 } 1668 1667 } else { 1669 1668 $query = new WP_Query( $custom_css_query_vars ); … … 1787 1786 } else { 1788 1787 $r = wp_insert_post( wp_slash( $post_data ), true ); 1789 1788 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 } 1793 1798 } 1794 1799 } 1795 1800 -
tests/phpunit/tests/customize/custom-css-setting.php
135 135 ) ); 136 136 $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' ); 137 137 138 remove_theme_mod( 'custom_css_post_id' ); 139 138 140 $this->assertEquals( $post_id, wp_get_custom_css_post()->ID ); 139 141 $this->assertEquals( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID ); 140 142 $this->assertEquals( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID ); … … 221 223 } 222 224 223 225 /** 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 /** 224 249 * Test crud methods on WP_Customize_Custom_CSS_Setting. 225 250 * 226 251 * @covers WP_Customize_Custom_CSS_Setting::value() … … 237 262 'post_status' => 'publish', 238 263 'post_type' => 'custom_css', 239 264 ) ); 265 remove_theme_mod( 'custom_css_post_id' ); 240 266 $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() ); 241 267 242 268 $this->wp_customize->set_post_value( $this->setting->id, '/*overridden*/' );