Make WordPress Core

Changeset 31031


Ignore:
Timestamp:
01/03/2015 04:09:12 AM (10 years ago)
Author:
wonderboymusic
Message:

Ensure that inline styles attached to conditional stylesheets are also conditional.

Adds unit test.

Props georgestephanis.
Fixes #29180.

Location:
trunk
Files:
2 edited

Legend:

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

    r30681 r31031  
    108108        }
    109109
    110         if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
    111             $tag = "<!--[if {$obj->extra['conditional']}]>\n" . $tag . "<![endif]-->\n";
     110        $conditional_pre = $conditional_post = '';
     111        if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) {
     112            $conditional_pre  = "<!--[if {$obj->extra['conditional']}]>\n";
     113            $conditional_post = "<![endif]-->\n";
    112114        }
    113115
    114116        if ( $this->do_concat ) {
     117            $this->print_html .= $conditional_pre;
    115118            $this->print_html .= $tag;
    116             if ( $inline_style = $this->print_inline_style( $handle, false ) )
     119            if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
    117120                $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
     121            }
     122            $this->print_html .= $conditional_post;
    118123        } else {
     124            echo $conditional_pre;
    119125            echo $tag;
    120126            $this->print_inline_style( $handle );
     127            echo $conditional_post;
    121128        }
    122129
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r29967 r31031  
    9797        $style .= "\tbackground: red;\n";
    9898        $style .= "}";
    99        
     99
    100100        $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
    101101        $expected .= "<style id='handle-inline-css' type='text/css'>\n";
     
    148148        $style1 .= "\tbackground: red;\n";
    149149        $style1 .= "}";
    150        
     150
    151151        $style2  = ".thing2 {\n";
    152152        $style2 .= "\tbackground: blue;\n";
     
    207207    }
    208208
     209    /**
     210     * Test to make sure that inline styles attached to conditional
     211     * stylesheets are also conditional.
     212     */
     213    public function test_conditional_inline_styles_are_also_conditional() {
     214        $expected = <<<CSS
     215<!--[if IE]>
     216<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />
     217<style id='handle-inline-css' type='text/css'>
     218a { color: blue; }
     219</style>
     220<![endif]-->
     221
     222CSS;
     223        wp_enqueue_style( 'handle', 'http://example.com', array(), 1 );
     224        wp_style_add_data( 'handle', 'conditional', 'IE' );
     225        wp_add_inline_style( 'handle', 'a { color: blue; }' );
     226
     227        $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     228    }
     229
    209230}
Note: See TracChangeset for help on using the changeset viewer.