Make WordPress Core

Ticket #24813: 24813.4.diff

File 24813.4.diff, 3.5 KB (added by atimmer, 13 years ago)
  • src/wp-includes/class.wp-styles.php

     
    8787
    8888                if ( $this->do_concat ) {
    8989                        $this->print_html .= $tag;
    90                         $this->print_html .= $this->print_inline_style( $handle, false );
     90                        $this->print_html .= sprintf( "<style type='text/css'>\n%s\n</style>\n", $this->print_inline_style( $handle, false ) );
    9191                } else {
    9292                        echo $tag;
    93                         echo $this->print_inline_style( $handle, false );
     93                        $this->print_inline_style( $handle );
    9494                }
    9595
    9696                return true;
  • src/wp-includes/functions.wp-styles.php

     
    7171                $wp_styles = new WP_Styles();
    7272        }
    7373
     74        if ( false !== stripos( $data, '</style>' ) ) {
     75                _doing_it_wrong( __FUNCTION__, 'Do not pass <style> tags to wp_add_inline_style()', '3.7' );
     76                $data = preg_replace( '<style[^>]*>(.*)</style>i', '$1', $data );
     77        }
     78
    7479        return $wp_styles->add_inline_style( $handle, $data );
    7580}
    7681
  • tests/phpunit/tests/dependencies/styles.php

     
    8686                // Cleanup
    8787                $wp_styles->base_url = $base_url_backup;
    8888        }
     89
     90        /**
     91         * Test if inline styles work
     92         * @ticket 24813
     93         */
     94        public function test_inline_styles() {
     95
     96                $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     97                $expected .= "<style type='text/css'>\n";
     98                $expected .= "background: red\n";
     99                $expected .= "</style>\n";
     100
     101                wp_enqueue_style( 'handle', 'example.com', array(), 1 );
     102                wp_add_inline_style( 'handle', 'background: red' );
     103
     104                // No styles left to print
     105                $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     106        }
     107
     108        /**
     109         * Test if inline styles work with concatination
     110         * @global WP_Styles $wp_styles
     111         * @ticket 24813
     112         */
     113        public function test_inline_styles_concat() {
     114
     115                global $wp_styles;
     116
     117                $wp_styles->do_concat = true;
     118                $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php
     119
     120                wp_enqueue_style( 'handle', 'example.com', array(), 1 );
     121                wp_add_inline_style( 'handle', 'background: red' );
     122
     123                $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     124                $expected .= "<style type='text/css'>\n";
     125                $expected .= "background: red\n";
     126                $expected .= "</style>\n";
     127
     128                wp_print_styles();
     129                $this->assertEquals( $expected, $wp_styles->print_html );
     130
     131        }
     132
     133        /**
     134         * Test if multiple inline styles work
     135         * @ticket 24813
     136         */
     137        public function test_multiple_inline_styles() {
     138
     139                $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     140                $expected .= "<style type='text/css'>\n";
     141                $expected .= "background: red\n";
     142                $expected .= "background: green\n";
     143                $expected .= "</style>\n";
     144
     145                wp_enqueue_style( 'handle', 'example.com', array(), 1 );
     146                wp_add_inline_style( 'handle', 'background: red' );
     147                wp_add_inline_style( 'handle', 'background: green' );
     148
     149                // No styles left to print
     150                $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     151
     152        }
     153
    89154}