Ticket #36449: 36449.batch.patch
File 36449.batch.patch, 7.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class.wp-styles.php
62 62 * @var string 63 63 */ 64 64 public $concat = ''; 65 /** 66 * If concatenating, holds arrays of data batched in dependency order. 67 * 'concat' holds the handles to concatenate (comma-separated), 68 * 'print_code' inline styles for handles in 'concat' (will be enclosed in '<style>' tags), 69 * 'print_html' HTML markup of styles and additional data and inline styles not in 'print_code'. 70 * 71 * @since 4.5 72 * @access public 73 * @var array 74 */ 75 public $concats = array( array( 'concat' => '', 'print_code' => '', 'print_html' => '' ) ); 65 76 66 77 /** 67 78 * Holds a string which contains style handles and their version. … … 83 94 public $do_concat = false; 84 95 85 96 /** 86 * Holds HTML markup of styles and additional data if concatenation87 * is enabled.88 *89 * @since 2.8.090 * @access public91 * @var string92 */93 public $print_html = '';94 95 /**96 * Holds inline styles if concatenation is enabled.97 *98 * @since 3.3.099 * @access public100 * @var string101 */102 public $print_code = '';103 104 /**105 97 * List of default directories. 106 98 * 107 99 * @since 2.8.0 … … 152 144 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 153 145 154 146 if ( $this->do_concat ) { 155 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { 156 $this->concat .= "$handle,"; 147 148 $in_default_dir = $this->in_default_dir( $obj->src ); 149 150 if ( $in_default_dir && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt'] ) ) { 151 $concat_idx = count( $this->concats ) - 1; 152 $this->concats[$concat_idx]['concat'] .= "$handle,"; 153 $this->concats[$concat_idx]['print_code'] .= $this->print_inline_style( $handle, false ); 157 154 $this->concat_version .= "$handle$ver"; 158 155 159 $this->print_code .= $this->print_inline_style( $handle, false );160 161 156 return true; 162 157 } 163 158 } … … 172 167 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { 173 168 $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); 174 169 if ( $this->do_concat ) { 175 $this->print_html .= $inline_style; 170 $concat_idx = count( $this->concats ) - 1; 171 $this->concats[$concat_idx]['print_html'] .= $inline_style; 176 172 } else { 177 173 echo $inline_style; 178 174 } … … 226 222 } 227 223 228 224 if ( $this->do_concat ) { 229 $this->print_html .= $conditional_pre; 230 $this->print_html .= $tag; 225 $concat_idx = count( $this->concats ) - 1; 226 $this->concats[$concat_idx]['print_html'] .= $conditional_pre; 227 $this->concats[$concat_idx]['print_html'] .= $tag; 231 228 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { 232 $this-> print_html.= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );229 $this->concats[$concat_idx]['print_html'] .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); 233 230 } 234 $this->print_html .= $conditional_post; 231 $this->concats[$concat_idx]['print_html'] .= $conditional_post; 232 // To maintain dependency order, need to bump batch to next level if wasn't concatenated above. 233 if ( ! ( $in_default_dir && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt'] ) ) ) { 234 $this->concats[] = array( 'concat' => '', 'print_code' => '', 'print_html' => '' ); 235 } 235 236 } else { 236 237 echo $conditional_pre; 237 238 echo $tag; … … 400 401 */ 401 402 public function reset() { 402 403 $this->do_concat = false; 403 $this->concat = '';404 $this->concats = array( array( 'concat' => '', 'print_code' => '', 'print_html' => '' ) ); 404 405 $this->concat_version = ''; 405 $this->print_html = '';406 406 } 407 407 } -
src/wp-includes/script-loader.php
1166 1166 if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP ) 1167 1167 $zip = 'gzip'; 1168 1168 1169 if ( $concat = trim( $wp_styles->concat, ', ' ) ) { 1170 $dir = $wp_styles->text_direction; 1171 $ver = $wp_styles->default_version; 1169 foreach ( $wp_styles->concats as $concat_entry ) { 1170 $concat = trim( $concat_entry['concat'], ', ' ); 1171 if ( '' !== $concat ) { 1172 $dir = $wp_styles->text_direction; 1173 $ver = $wp_styles->default_version; 1172 1174 1173 $concat = str_split( $concat, 128 );1174 $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat );1175 $concat = str_split( $concat, 128 ); 1176 $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat ); 1175 1177 1176 $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=' . $ver; 1177 echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n"; 1178 $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=' . $ver; 1179 echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n"; 1180 } 1178 1181 1179 if ( !empty($wp_styles->print_code)) {1182 if ( '' !== $concat_entry['print_code'] ) { 1180 1183 echo "<style type='text/css'>\n"; 1181 echo $ wp_styles->print_code;1184 echo $concat_entry['print_code']; 1182 1185 echo "\n</style>\n"; 1183 1186 } 1187 1188 if ( '' !== $concat_entry['print_html'] ) { 1189 echo $concat_entry['print_html']; 1190 } 1184 1191 } 1185 1186 if ( !empty($wp_styles->print_html) )1187 echo $wp_styles->print_html;1188 1192 } 1189 1193 1190 1194 /** -
tests/phpunit/tests/dependencies/styles.php
136 136 wp_add_inline_style( 'handle', $style ); 137 137 138 138 wp_print_styles(); 139 $this->assertEquals( $expected, $wp_styles->print_html ); 139 $print_styles = get_echo( '_print_styles' ); 140 $this->assertEquals( $expected, $print_styles ); 140 141 141 142 } 142 143 … … 298 299 ), 299 300 ); 300 301 } 302 303 /** 304 * @ticket wp_style_conditional_concat_dependency 305 */ 306 public function test_wp_style_conditional_concat_dependency() { 307 global $wp_styles; 308 309 $wp_styles->do_concat = true; 310 $wp_styles->default_dirs = array( '/directory/' ); 311 $wp_styles->default_version = 1; 312 313 wp_enqueue_style( 'one', '/directory/one.js', array(), 1 ); 314 wp_enqueue_style( 'two', '/directory/two.js', array(), 1 ); 315 wp_enqueue_style( 'three', '/directory/three.js', array( 'one' ), 1 ); 316 317 wp_style_add_data( 'one', 'conditional', 'blah' ); 318 319 $wp_print_styles = get_echo( 'wp_print_styles' ); 320 $print_styles = get_echo( '_print_styles' ); 321 322 $expected = "<!--[if blah]>\n"; 323 $expected .= "<link rel='stylesheet' id='one-css' href='/directory/one.js?ver=1' type='text/css' media='all' />\n"; 324 $expected .= "<![endif]-->\n"; 325 $expected .= "<link rel='stylesheet' href='/wp-admin/load-styles.php?c=0&dir=ltr&load%5B%5D=two,three&ver=1' type='text/css' media='all' />\n"; 326 327 $this->assertEquals( $expected, $print_styles ); 328 $this->assertEquals( '', $wp_print_styles ); 329 } 301 330 }