From d699ce8b1315912cb3fb1aede9d3fadf7aec397a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 3 Jan 2015 04:09:12 +0000 Subject: [PATCH] Ensure that inline styles attached to conditional stylesheets are also conditional. Adds unit test. Props georgestephanis. Fixes #29180. git-svn-id: https://develop.svn.wordpress.org/trunk@31031 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class.wp-styles.php | 13 ++++++++--- tests/phpunit/tests/dependencies/styles.php | 25 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class.wp-styles.php b/src/wp-includes/class.wp-styles.php index eb160670ca..46cb913bd3 100644 --- a/src/wp-includes/class.wp-styles.php +++ b/src/wp-includes/class.wp-styles.php @@ -107,17 +107,24 @@ class WP_Styles extends WP_Dependencies { } } - if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) { - $tag = "\n"; + $conditional_pre = $conditional_post = ''; + if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) { + $conditional_pre = "\n"; } if ( $this->do_concat ) { + $this->print_html .= $conditional_pre; $this->print_html .= $tag; - if ( $inline_style = $this->print_inline_style( $handle, false ) ) + if ( $inline_style = $this->print_inline_style( $handle, false ) ) { $this->print_html .= sprintf( "\n", esc_attr( $handle ), $inline_style ); + } + $this->print_html .= $conditional_post; } else { + echo $conditional_pre; echo $tag; $this->print_inline_style( $handle ); + echo $conditional_post; } return true; diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index b576b20371..6788d8af9f 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -96,7 +96,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { $style = ".thing {\n"; $style .= "\tbackground: red;\n"; $style .= "}"; - + $expected = "\n"; $expected .= " + + +CSS; + wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); + wp_style_add_data( 'handle', 'conditional', 'IE' ); + wp_add_inline_style( 'handle', 'a { color: blue; }' ); + + $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); + } + }