Changeset 25786
- Timestamp:
- 10/15/2013 02:34:33 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/class.wp-styles.php (modified) (1 diff)
-
src/wp-includes/functions.wp-styles.php (modified) (2 diffs)
-
tests/phpunit/tests/dependencies/styles.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class.wp-styles.php
r25202 r25786 88 88 if ( $this->do_concat ) { 89 89 $this->print_html .= $tag; 90 $this->print_html .= $this->print_inline_style( $handle, false ); 90 if ( $inline_style = $this->print_inline_style( $handle, false ) ) 91 $this->print_html .= sprintf( "<style type='text/css'>\n%s\n</style>\n", $inline_style ); 91 92 } else { 92 93 echo $tag; 93 echo $this->print_inline_style( $handle, false );94 $this->print_inline_style( $handle ); 94 95 } 95 96 -
trunk/src/wp-includes/functions.wp-styles.php
r25594 r25786 15 15 * passing an array with one string prints that style, 16 16 * and passing an array of strings prints those styles. 17 * 17 * 18 18 * @see do_action() Calls 'wp_print_styles' hook. 19 19 * @global WP_Styles $wp_styles The WP_Styles object for printing styles. … … 70 70 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 71 71 $wp_styles = new WP_Styles(); 72 } 73 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 = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); 72 77 } 73 78 -
trunk/tests/phpunit/tests/dependencies/styles.php
r25376 r25786 87 87 $wp_styles->base_url = $base_url_backup; 88 88 } 89 90 /** 91 * Test if inline styles work 92 * @ticket 24813 93 */ 94 public function test_inline_styles() { 95 96 $style = ".thing {\n"; 97 $style .= "\tbackground: red;\n"; 98 $style .= "}"; 99 100 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 101 $expected .= "<style type='text/css'>\n"; 102 $expected .= "$style\n"; 103 $expected .= "</style>\n"; 104 105 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); 106 wp_add_inline_style( 'handle', $style ); 107 108 // No styles left to print 109 $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); 110 } 111 112 /** 113 * Test if inline styles work with concatination 114 * @global WP_Styles $wp_styles 115 * @ticket 24813 116 */ 117 public function test_inline_styles_concat() { 118 119 global $wp_styles; 120 121 $wp_styles->do_concat = true; 122 $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php 123 124 $style = ".thing {\n"; 125 $style .= "\tbackground: red;\n"; 126 $style .= "}"; 127 128 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 129 $expected .= "<style type='text/css'>\n"; 130 $expected .= "$style\n"; 131 $expected .= "</style>\n"; 132 133 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); 134 wp_add_inline_style( 'handle', $style ); 135 136 wp_print_styles(); 137 $this->assertEquals( $expected, $wp_styles->print_html ); 138 139 } 140 141 /** 142 * Test if multiple inline styles work 143 * @ticket 24813 144 */ 145 public function test_multiple_inline_styles() { 146 147 $style1 = ".thing1 {\n"; 148 $style1 .= "\tbackground: red;\n"; 149 $style1 .= "}"; 150 151 $style2 = ".thing2 {\n"; 152 $style2 .= "\tbackground: blue;\n"; 153 $style2 .= "}"; 154 155 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 156 $expected .= "<style type='text/css'>\n"; 157 $expected .= "$style1\n"; 158 $expected .= "$style2\n"; 159 $expected .= "</style>\n"; 160 161 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); 162 wp_add_inline_style( 'handle', $style1 ); 163 wp_add_inline_style( 'handle', $style2 ); 164 165 // No styles left to print 166 $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); 167 168 } 169 170 /** 171 * Test if a plugin doing it the wrong way still works 172 * 173 * @expectedIncorrectUsage wp_add_inline_style 174 * @ticket 24813 175 */ 176 public function test_plugin_doing_inline_styles_wrong() { 177 178 $style = "<style type='text/css'>\n"; 179 $style .= ".thing {\n"; 180 $style .= "\tbackground: red;\n"; 181 $style .= "}\n"; 182 $style .= "</style>"; 183 184 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 185 $expected .= "$style\n"; 186 187 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); 188 189 wp_add_inline_style( 'handle', $style ); 190 191 $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); 192 193 } 194 195 /** 196 * Test to make sure <style> tags aren't output if there are no inline styles. 197 * @ticket 24813 198 */ 199 public function test_unnecessary_style_tags() { 200 201 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 202 203 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); 204 205 $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); 206 207 } 208 89 209 }
Note: See TracChangeset
for help on using the changeset viewer.