Changeset 58878 for trunk/src/wp-includes/class-wp-scripts.php
- Timestamp:
- 08/10/2024 10:58:07 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-scripts.php
r57533 r58878 290 290 } 291 291 292 $src = $obj->src;293 $strategy = $this->get_eligible_loading_strategy( $handle );294 $intended_strategy = (string) $this->get_data( $handle, 'strategy' );295 $ cond_before= '';296 $ cond_after= '';297 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';292 $src = $obj->src; 293 $strategy = $this->get_eligible_loading_strategy( $handle ); 294 $intended_strategy = (string) $this->get_data( $handle, 'strategy' ); 295 $ie_conditional_prefix = ''; 296 $ie_conditional_suffix = ''; 297 $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; 298 298 299 299 if ( ! $this->is_delayed_strategy( $intended_strategy ) ) { … … 321 321 322 322 if ( $conditional ) { 323 $ cond_before= "<!--[if {$conditional}]>\n";324 $ cond_after= "<![endif]-->\n";323 $ie_conditional_prefix = "<!--[if {$conditional}]>\n"; 324 $ie_conditional_suffix = "<![endif]-->\n"; 325 325 } 326 326 … … 329 329 330 330 if ( $before_script || $after_script ) { 331 $inline_script_tag = $ cond_before . $before_script . $after_script . $cond_after;331 $inline_script_tag = $ie_conditional_prefix . $before_script . $after_script . $ie_conditional_suffix; 332 332 } else { 333 333 $inline_script_tag = ''; … … 354 354 * @param string $handle Script handle. 355 355 */ 356 $ srce= apply_filters( 'script_loader_src', $src, $handle );356 $filtered_src = apply_filters( 'script_loader_src', $src, $handle ); 357 357 358 358 if ( 359 $this->in_default_dir( $ srce)359 $this->in_default_dir( $filtered_src ) 360 360 && ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) ) 361 361 ) { … … 365 365 _print_scripts(); 366 366 $this->reset(); 367 } elseif ( $this->in_default_dir( $ srce) && ! $conditional ) {367 } elseif ( $this->in_default_dir( $filtered_src ) && ! $conditional ) { 368 368 $this->print_code .= $this->print_extra_script( $handle, false ); 369 369 $this->concat .= "$handle,"; … … 379 379 380 380 if ( $has_conditional_data ) { 381 echo $ cond_before;381 echo $ie_conditional_prefix; 382 382 } 383 383 … … 385 385 386 386 if ( $has_conditional_data ) { 387 echo $ cond_after;387 echo $ie_conditional_suffix; 388 388 } 389 389 … … 426 426 $attr['data-wp-strategy'] = $intended_strategy; 427 427 } 428 $tag = $translations . $ cond_before. $before_script;428 $tag = $translations . $ie_conditional_prefix . $before_script; 429 429 $tag .= wp_get_script_tag( $attr ); 430 $tag .= $after_script . $ cond_after;430 $tag .= $after_script . $ie_conditional_suffix; 431 431 432 432 /** … … 627 627 public function set_group( $handle, $recursion, $group = false ) { 628 628 if ( isset( $this->registered[ $handle ]->args ) && 1 === $this->registered[ $handle ]->args ) { 629 $ grp = 1;629 $calculated_group = 1; 630 630 } else { 631 $ grp = (int) $this->get_data( $handle, 'group' );632 } 633 634 if ( false !== $group && $ grp > $group ) {635 $ grp = $group;636 } 637 638 return parent::set_group( $handle, $recursion, $ grp );631 $calculated_group = (int) $this->get_data( $handle, 'group' ); 632 } 633 634 if ( false !== $group && $calculated_group > $group ) { 635 $calculated_group = $group; 636 } 637 638 return parent::set_group( $handle, $recursion, $calculated_group ); 639 639 } 640 640 … … 724 724 */ 725 725 public function all_deps( $handles, $recursion = false, $group = false ) { 726 $r = parent::all_deps( $handles, $recursion, $group );726 $result = parent::all_deps( $handles, $recursion, $group ); 727 727 if ( ! $recursion ) { 728 728 /** … … 735 735 $this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); 736 736 } 737 return $r ;737 return $result; 738 738 } 739 739 … … 890 890 */ 891 891 private function get_eligible_loading_strategy( $handle ) { 892 $intended = (string) $this->get_data( $handle, 'strategy' );892 $intended_strategy = (string) $this->get_data( $handle, 'strategy' ); 893 893 894 894 // Bail early if there is no intended strategy. 895 if ( ! $intended ) {895 if ( ! $intended_strategy ) { 896 896 return ''; 897 897 } … … 901 901 * strategies, since 'async' can fallback to 'defer', but not vice-versa. 902 902 */ 903 $initial = ( 'defer' === $intended) ? array( 'defer' ) : null;904 905 $eligible = $this->filter_eligible_strategies( $handle, $initial);903 $initial_strategy = ( 'defer' === $intended_strategy ) ? array( 'defer' ) : null; 904 905 $eligible_strategies = $this->filter_eligible_strategies( $handle, $initial_strategy ); 906 906 907 907 // Return early once we know the eligible strategy is blocking. 908 if ( empty( $eligible ) ) {908 if ( empty( $eligible_strategies ) ) { 909 909 return ''; 910 910 } 911 911 912 return in_array( 'async', $eligible , true ) ? 'async' : 'defer';912 return in_array( 'async', $eligible_strategies, true ) ? 'async' : 'defer'; 913 913 } 914 914 … … 918 918 * @since 6.3.0 919 919 * 920 * @param string $handle The script handle.921 * @param string[]|null $eligible Optional. The list of strategies to filter. Default null.922 * @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.920 * @param string $handle The script handle. 921 * @param string[]|null $eligible_strategies Optional. The list of strategies to filter. Default null. 922 * @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops. 923 923 * @return string[] A list of eligible loading strategies that could be used. 924 924 */ 925 private function filter_eligible_strategies( $handle, $eligible = null, $checked = array() ) {925 private function filter_eligible_strategies( $handle, $eligible_strategies = null, $checked = array() ) { 926 926 // If no strategies are being passed, all strategies are eligible. 927 if ( null === $eligible ) {928 $eligible = $this->delayed_strategies;927 if ( null === $eligible_strategies ) { 928 $eligible_strategies = $this->delayed_strategies; 929 929 } 930 930 931 931 // If this handle was already checked, return early. 932 932 if ( isset( $checked[ $handle ] ) ) { 933 return $eligible ;933 return $eligible_strategies; 934 934 } 935 935 … … 939 939 // If this handle isn't registered, don't filter anything and return. 940 940 if ( ! isset( $this->registered[ $handle ] ) ) { 941 return $eligible ;941 return $eligible_strategies; 942 942 } 943 943 944 944 // If the handle is not enqueued, don't filter anything and return. 945 945 if ( ! $this->query( $handle, 'enqueued' ) ) { 946 return $eligible ;946 return $eligible_strategies; 947 947 } 948 948 … … 962 962 // If the intended strategy is 'defer', filter out 'async'. 963 963 if ( 'defer' === $intended_strategy ) { 964 $eligible = array( 'defer' );964 $eligible_strategies = array( 'defer' ); 965 965 } 966 966 … … 970 970 foreach ( $dependents as $dependent ) { 971 971 // Bail early once we know the eligible strategy is blocking. 972 if ( empty( $eligible ) ) {972 if ( empty( $eligible_strategies ) ) { 973 973 return array(); 974 974 } 975 975 976 $eligible = $this->filter_eligible_strategies( $dependent, $eligible, $checked );977 } 978 979 return $eligible ;976 $eligible_strategies = $this->filter_eligible_strategies( $dependent, $eligible_strategies, $checked ); 977 } 978 979 return $eligible_strategies; 980 980 } 981 981
Note: See TracChangeset
for help on using the changeset viewer.