Ticket #42804: wp-includes.patch
File wp-includes.patch, 13.6 KB (added by , 7 years ago) |
---|
-
trunk/wp-includes/class.wp-scripts.php
145 145 * 146 146 * @param WP_Scripts $this WP_Scripts instance (passed by reference). 147 147 */ 148 do_action_ref_array( 'wp_default_scripts', array( &$this) );148 do_action_ref_array( 'wp_default_scripts', array(&$this) ); 149 149 } 150 150 151 151 /** … … 196 196 * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. 197 197 */ 198 198 public function print_extra_script( $handle, $echo = true ) { 199 if ( ! $output = $this->get_data( $handle, 'data' ) ) {199 if ( !$output = $this->get_data( $handle, 'data' ) ) 200 200 return; 201 }202 201 203 if ( ! $echo ) {202 if ( !$echo ) 204 203 return $output; 205 }206 204 207 echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5205 echo "<script>\n"; // CDATA and type='text/javascript' is not needed for HTML 5 208 206 echo "/* <![CDATA[ */\n"; 209 207 echo "$output\n"; 210 208 echo "/* ]]> */\n"; … … 226 224 * @return bool True on success, false on failure. 227 225 */ 228 226 public function do_item( $handle, $group = false ) { 229 if ( ! parent::do_item( $handle ) ) {227 if ( !parent::do_item($handle) ) 230 228 return false; 231 }232 229 233 if ( 0 === $group && $this->groups[ $handle] > 0 ) {230 if ( 0 === $group && $this->groups[$handle] > 0 ) { 234 231 $this->in_footer[] = $handle; 235 232 return false; 236 233 } 237 234 238 if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {235 if ( false === $group && in_array($handle, $this->in_footer, true) ) 239 236 $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 240 }241 237 242 $obj = $this->registered[ $handle];238 $obj = $this->registered[$handle]; 243 239 244 240 if ( null === $obj->ver ) { 245 241 $ver = ''; … … 247 243 $ver = $obj->ver ? $obj->ver : $this->default_version; 248 244 } 249 245 250 if ( isset( $this->args[ $handle ] ) ) { 251 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; 252 } 246 if ( isset($this->args[$handle]) ) 247 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 253 248 254 $src 249 $src = $obj->src; 255 250 $cond_before = $cond_after = ''; 256 251 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; 257 252 258 253 if ( $conditional ) { 259 254 $cond_before = "<!--[if {$conditional}]>\n"; 260 $cond_after 255 $cond_after = "<![endif]-->\n"; 261 256 } 262 257 263 258 $before_handle = $this->print_inline_script( $handle, 'before', false ); 264 $after_handle 259 $after_handle = $this->print_inline_script( $handle, 'after', false ); 265 260 266 261 if ( $before_handle ) { 267 $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle );262 $before_handle = sprintf( "<script>\n%s\n</script>\n", $before_handle ); 268 263 } 269 264 270 265 if ( $after_handle ) { 271 $after_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $after_handle );266 $after_handle = sprintf( "<script>\n%s\n</script>\n", $after_handle ); 272 267 } 273 268 274 269 if ( $this->do_concat ) { … … 289 284 _print_scripts(); 290 285 $this->reset(); 291 286 } elseif ( $this->in_default_dir( $srce ) && ! $conditional ) { 292 $this->print_code 293 $this->concat 287 $this->print_code .= $this->print_extra_script( $handle, false ); 288 $this->concat .= "$handle,"; 294 289 $this->concat_version .= "$handle$ver"; 295 290 return true; 296 291 } else { … … 320 315 $src = $this->base_url . $src; 321 316 } 322 317 323 if ( ! empty( $ver ) ) {318 if ( ! empty( $ver ) ) 324 319 $src = add_query_arg( 'ver', $ver, $src ); 325 }326 320 327 321 /** This filter is documented in wp-includes/class.wp-scripts.php */ 328 322 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); 329 323 330 if ( ! $src ) {324 if ( ! $src ) 331 325 return true; 332 }333 326 334 $tag = "{$cond_before}{$before_handle}<script type='text/javascript'src='$src'></script>\n{$after_handle}{$cond_after}";327 $tag = "{$cond_before}{$before_handle}<script src='$src'></script>\n{$after_handle}{$cond_after}"; 335 328 336 329 /** 337 330 * Filters the HTML script tag of an enqueued script. … … 401 394 $output = trim( implode( "\n", $output ), "\n" ); 402 395 403 396 if ( $echo ) { 404 printf( "<script type='text/javascript'>\n%s\n</script>\n", $output );397 printf( "<script>\n%s\n</script>\n", $output ); 405 398 } 406 399 407 400 return $output; … … 418 411 * @return bool 419 412 */ 420 413 public function localize( $handle, $object_name, $l10n ) { 421 if ( $handle === 'jquery' ) {414 if ( $handle === 'jquery' ) 422 415 $handle = 'jquery-core'; 423 }424 416 425 if ( is_array( $l10n ) && isset( $l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present417 if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present 426 418 $after = $l10n['l10n_print_after']; 427 unset( $l10n['l10n_print_after']);419 unset($l10n['l10n_print_after']); 428 420 } 429 421 430 422 foreach ( (array) $l10n as $key => $value ) { 431 if ( ! is_scalar( $value ) ) {423 if ( !is_scalar($value) ) 432 424 continue; 433 }434 425 435 $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');426 $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); 436 427 } 437 428 438 429 $script = "var $object_name = " . wp_json_encode( $l10n ) . ';'; 439 430 440 if ( ! empty( $after ) ) {431 if ( !empty($after) ) 441 432 $script .= "\n$after;"; 442 }443 433 444 434 $data = $this->get_data( $handle, 'data' ); 445 435 446 if ( ! empty( $data ) ) {436 if ( !empty( $data ) ) 447 437 $script = "$data\n$script"; 448 }449 438 450 439 return $this->add_data( $handle, 'data', $script ); 451 440 } … … 463 452 * @return bool Not already in the group or a lower group 464 453 */ 465 454 public function set_group( $handle, $recursion, $group = false ) { 466 if ( isset( $this->registered[ $handle ]->args ) && $this->registered[ $handle ]->args === 1 ) {455 if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 ) 467 456 $grp = 1; 468 } else {457 else 469 458 $grp = (int) $this->get_data( $handle, 'group' ); 470 }471 459 472 if ( false !== $group && $grp > $group ) {460 if ( false !== $group && $grp > $group ) 473 461 $grp = $group; 474 }475 462 476 463 return parent::set_group( $handle, $recursion, $grp ); 477 464 } … … 478 465 479 466 /** 480 467 * Determines script dependencies. 481 468 * 482 469 * @since 2.1.0 483 470 * 484 471 * @see WP_Dependencies::all_deps() … … 513 500 * @return array Handles of items that have been processed. 514 501 */ 515 502 public function do_head_items() { 516 $this->do_items( false, 0);503 $this->do_items(false, 0); 517 504 return $this->done; 518 505 } 519 506 … … 527 514 * @return array Handles of items that have been processed. 528 515 */ 529 516 public function do_footer_items() { 530 $this->do_items( false, 1);517 $this->do_items(false, 1); 531 518 return $this->done; 532 519 } 533 520 … … 562 549 * @since 2.8.0 563 550 */ 564 551 public function reset() { 565 $this->do_concat 566 $this->print_code 567 $this->concat 552 $this->do_concat = false; 553 $this->print_code = ''; 554 $this->concat = ''; 568 555 $this->concat_version = ''; 569 $this->print_html 570 $this->ext_version 571 $this->ext_handles 556 $this->print_html = ''; 557 $this->ext_version = ''; 558 $this->ext_handles = ''; 572 559 } 573 560 } -
trunk/wp-includes/class.wp-styles.php
113 113 * 114 114 * @param WP_Styles $this WP_Styles instance (passed by reference). 115 115 */ 116 do_action_ref_array( 'wp_default_styles', array( &$this) );116 do_action_ref_array( 'wp_default_styles', array(&$this) ); 117 117 } 118 118 119 119 /** … … 127 127 * @return bool True on success, false on failure. 128 128 */ 129 129 public function do_item( $handle ) { 130 if ( ! parent::do_item( $handle ) ) {130 if ( !parent::do_item($handle) ) 131 131 return false; 132 }133 132 134 $obj = $this->registered[ $handle];135 if ( null === $obj->ver ) {133 $obj = $this->registered[$handle]; 134 if ( null === $obj->ver ) 136 135 $ver = ''; 137 } else {136 else 138 137 $ver = $obj->ver ? $obj->ver : $this->default_version; 139 }140 138 141 if ( isset( $this->args[ $handle ] ) ) { 142 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; 143 } 139 if ( isset($this->args[$handle]) ) 140 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 144 141 145 142 if ( $this->do_concat ) { 146 if ( $this->in_default_dir( $obj->src ) && ! isset( $obj->extra['conditional'] ) && ! isset( $obj->extra['alt']) ) {147 $this->concat 143 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { 144 $this->concat .= "$handle,"; 148 145 $this->concat_version .= "$handle$ver"; 149 146 150 147 $this->print_code .= $this->print_inline_style( $handle, false ); … … 153 150 } 154 151 } 155 152 156 if ( isset( $obj->args ) ) {153 if ( isset($obj->args) ) 157 154 $media = esc_attr( $obj->args ); 158 } else {155 else 159 156 $media = 'all'; 160 }161 157 162 158 // A single item may alias a set of items, by having dependencies, but no source. 163 159 if ( ! $obj->src ) { 164 160 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { 165 $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );161 $inline_style = sprintf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); 166 162 if ( $this->do_concat ) { 167 163 $this->print_html .= $inline_style; 168 164 } else { … … 177 173 return true; 178 174 } 179 175 180 $rel = isset( $obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';181 $title = isset( $obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';176 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; 177 $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; 182 178 183 179 /** 184 180 * Filters the HTML link tag of an enqueued style. … … 192 188 * @param string $href The stylesheet's source URL. 193 189 * @param string $media The stylesheet's media attribute. 194 190 */ 195 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media 196 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl']) && $obj->extra['rtl'] ) {191 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); 192 if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) { 197 193 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { 198 $suffix 199 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));194 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; 195 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" )); 200 196 } else { 201 197 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); 202 198 } … … 221 217 $this->print_html .= $conditional_pre; 222 218 $this->print_html .= $tag; 223 219 if ( $inline_style = $this->print_inline_style( $handle, false ) ) { 224 $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );220 $this->print_html .= sprintf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); 225 221 } 226 222 $this->print_html .= $conditional_post; 227 223 } else { … … 281 277 return $output; 282 278 } 283 279 284 printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output );280 printf( "<style id='%s-inline-css'>\n%s\n</style>\n", esc_attr( $handle ), $output ); 285 281 286 282 return true; 287 283 } … … 324 320 * @return string Style's fully-qualified URL. 325 321 */ 326 322 public function _css_href( $src, $ver, $handle ) { 327 if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url) ) ) {323 if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 328 324 $src = $this->base_url . $src; 329 325 } 330 326 331 if ( ! empty( $ver ) ) { 332 $src = add_query_arg( 'ver', $ver, $src ); 333 } 327 if ( !empty($ver) ) 328 $src = add_query_arg('ver', $ver, $src); 334 329 335 330 /** 336 331 * Filters an enqueued style's fully-qualified URL. … … 353 348 * @return bool True if found, false if not. 354 349 */ 355 350 public function in_default_dir( $src ) { 356 if ( ! $this->default_dirs ) {351 if ( ! $this->default_dirs ) 357 352 return true; 358 }359 353 360 354 foreach ( (array) $this->default_dirs as $test ) { 361 if ( 0 === strpos( $src, $test ) ) {355 if ( 0 === strpos($src, $test) ) 362 356 return true; 363 }364 357 } 365 358 return false; 366 359 } … … 377 370 * @return array Handles of items that have been processed. 378 371 */ 379 372 public function do_footer_items() { 380 $this->do_items( false, 1);373 $this->do_items(false, 1); 381 374 return $this->done; 382 375 } 383 376 … … 387 380 * @since 3.3.0 388 381 */ 389 382 public function reset() { 390 $this->do_concat 391 $this->concat 383 $this->do_concat = false; 384 $this->concat = ''; 392 385 $this->concat_version = ''; 393 $this->print_html 386 $this->print_html = ''; 394 387 } 395 388 }