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
This commit is contained in:
Scott Taylor 2015-01-03 04:09:12 +00:00
parent c69dbc8b5a
commit d699ce8b13
2 changed files with 33 additions and 5 deletions

View File

@ -107,17 +107,24 @@ class WP_Styles extends WP_Dependencies {
} }
} }
if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) { $conditional_pre = $conditional_post = '';
$tag = "<!--[if {$obj->extra['conditional']}]>\n" . $tag . "<![endif]-->\n"; if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) {
$conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n";
$conditional_post = "<![endif]-->\n";
} }
if ( $this->do_concat ) { if ( $this->do_concat ) {
$this->print_html .= $conditional_pre;
$this->print_html .= $tag; $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( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
}
$this->print_html .= $conditional_post;
} else { } else {
echo $conditional_pre;
echo $tag; echo $tag;
$this->print_inline_style( $handle ); $this->print_inline_style( $handle );
echo $conditional_post;
} }
return true; return true;

View File

@ -96,7 +96,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase {
$style = ".thing {\n"; $style = ".thing {\n";
$style .= "\tbackground: red;\n"; $style .= "\tbackground: red;\n";
$style .= "}"; $style .= "}";
$expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";
$expected .= "<style id='handle-inline-css' type='text/css'>\n"; $expected .= "<style id='handle-inline-css' type='text/css'>\n";
$expected .= "$style\n"; $expected .= "$style\n";
@ -147,7 +147,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase {
$style1 = ".thing1 {\n"; $style1 = ".thing1 {\n";
$style1 .= "\tbackground: red;\n"; $style1 .= "\tbackground: red;\n";
$style1 .= "}"; $style1 .= "}";
$style2 = ".thing2 {\n"; $style2 = ".thing2 {\n";
$style2 .= "\tbackground: blue;\n"; $style2 .= "\tbackground: blue;\n";
$style2 .= "}"; $style2 .= "}";
@ -206,4 +206,25 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase {
} }
/**
* Test to make sure that inline styles attached to conditional
* stylesheets are also conditional.
*/
public function test_conditional_inline_styles_are_also_conditional() {
$expected = <<<CSS
<!--[if IE]>
<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />
<style id='handle-inline-css' type='text/css'>
a { color: blue; }
</style>
<![endif]-->
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' ) );
}
} }