mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 00:58:46 +01:00
Code Quality: Clarify variable names in dependency classes.
Renames several variables in the `WP_Scripts` and `WP_Styles` classes to clarify their purpose for developers reading the code. Props peterwilsoncc, sergeybiryukov. See #61607. Built from https://develop.svn.wordpress.org/trunk@58878 git-svn-id: http://core.svn.wordpress.org/trunk@58274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
98e51518b3
commit
bf103e6621
@ -289,12 +289,12 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];
|
||||
}
|
||||
|
||||
$src = $obj->src;
|
||||
$strategy = $this->get_eligible_loading_strategy( $handle );
|
||||
$intended_strategy = (string) $this->get_data( $handle, 'strategy' );
|
||||
$cond_before = '';
|
||||
$cond_after = '';
|
||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||
$src = $obj->src;
|
||||
$strategy = $this->get_eligible_loading_strategy( $handle );
|
||||
$intended_strategy = (string) $this->get_data( $handle, 'strategy' );
|
||||
$ie_conditional_prefix = '';
|
||||
$ie_conditional_suffix = '';
|
||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||
|
||||
if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {
|
||||
$intended_strategy = '';
|
||||
@ -320,15 +320,15 @@ class WP_Scripts extends WP_Dependencies {
|
||||
}
|
||||
|
||||
if ( $conditional ) {
|
||||
$cond_before = "<!--[if {$conditional}]>\n";
|
||||
$cond_after = "<![endif]-->\n";
|
||||
$ie_conditional_prefix = "<!--[if {$conditional}]>\n";
|
||||
$ie_conditional_suffix = "<![endif]-->\n";
|
||||
}
|
||||
|
||||
$before_script = $this->get_inline_script_tag( $handle, 'before' );
|
||||
$after_script = $this->get_inline_script_tag( $handle, 'after' );
|
||||
|
||||
if ( $before_script || $after_script ) {
|
||||
$inline_script_tag = $cond_before . $before_script . $after_script . $cond_after;
|
||||
$inline_script_tag = $ie_conditional_prefix . $before_script . $after_script . $ie_conditional_suffix;
|
||||
} else {
|
||||
$inline_script_tag = '';
|
||||
}
|
||||
@ -353,10 +353,10 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @param string $src Script loader source path.
|
||||
* @param string $handle Script handle.
|
||||
*/
|
||||
$srce = apply_filters( 'script_loader_src', $src, $handle );
|
||||
$filtered_src = apply_filters( 'script_loader_src', $src, $handle );
|
||||
|
||||
if (
|
||||
$this->in_default_dir( $srce )
|
||||
$this->in_default_dir( $filtered_src )
|
||||
&& ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) )
|
||||
) {
|
||||
$this->do_concat = false;
|
||||
@ -364,7 +364,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
// Have to print the so-far concatenated scripts right away to maintain the right order.
|
||||
_print_scripts();
|
||||
$this->reset();
|
||||
} elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
|
||||
} elseif ( $this->in_default_dir( $filtered_src ) && ! $conditional ) {
|
||||
$this->print_code .= $this->print_extra_script( $handle, false );
|
||||
$this->concat .= "$handle,";
|
||||
$this->concat_version .= "$handle$ver";
|
||||
@ -378,13 +378,13 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
|
||||
|
||||
if ( $has_conditional_data ) {
|
||||
echo $cond_before;
|
||||
echo $ie_conditional_prefix;
|
||||
}
|
||||
|
||||
$this->print_extra_script( $handle );
|
||||
|
||||
if ( $has_conditional_data ) {
|
||||
echo $cond_after;
|
||||
echo $ie_conditional_suffix;
|
||||
}
|
||||
|
||||
// A single item may alias a set of items, by having dependencies, but no source.
|
||||
@ -425,9 +425,9 @@ class WP_Scripts extends WP_Dependencies {
|
||||
if ( $intended_strategy ) {
|
||||
$attr['data-wp-strategy'] = $intended_strategy;
|
||||
}
|
||||
$tag = $translations . $cond_before . $before_script;
|
||||
$tag = $translations . $ie_conditional_prefix . $before_script;
|
||||
$tag .= wp_get_script_tag( $attr );
|
||||
$tag .= $after_script . $cond_after;
|
||||
$tag .= $after_script . $ie_conditional_suffix;
|
||||
|
||||
/**
|
||||
* Filters the HTML script tag of an enqueued script.
|
||||
@ -626,16 +626,16 @@ class WP_Scripts extends WP_Dependencies {
|
||||
*/
|
||||
public function set_group( $handle, $recursion, $group = false ) {
|
||||
if ( isset( $this->registered[ $handle ]->args ) && 1 === $this->registered[ $handle ]->args ) {
|
||||
$grp = 1;
|
||||
$calculated_group = 1;
|
||||
} else {
|
||||
$grp = (int) $this->get_data( $handle, 'group' );
|
||||
$calculated_group = (int) $this->get_data( $handle, 'group' );
|
||||
}
|
||||
|
||||
if ( false !== $group && $grp > $group ) {
|
||||
$grp = $group;
|
||||
if ( false !== $group && $calculated_group > $group ) {
|
||||
$calculated_group = $group;
|
||||
}
|
||||
|
||||
return parent::set_group( $handle, $recursion, $grp );
|
||||
return parent::set_group( $handle, $recursion, $calculated_group );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -723,7 +723,7 @@ JS;
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public function all_deps( $handles, $recursion = false, $group = false ) {
|
||||
$r = parent::all_deps( $handles, $recursion, $group );
|
||||
$result = parent::all_deps( $handles, $recursion, $group );
|
||||
if ( ! $recursion ) {
|
||||
/**
|
||||
* Filters the list of script dependencies left to print.
|
||||
@ -734,7 +734,7 @@ JS;
|
||||
*/
|
||||
$this->to_do = apply_filters( 'print_scripts_array', $this->to_do );
|
||||
}
|
||||
return $r;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -889,10 +889,10 @@ JS;
|
||||
* @return string The best eligible loading strategy.
|
||||
*/
|
||||
private function get_eligible_loading_strategy( $handle ) {
|
||||
$intended = (string) $this->get_data( $handle, 'strategy' );
|
||||
$intended_strategy = (string) $this->get_data( $handle, 'strategy' );
|
||||
|
||||
// Bail early if there is no intended strategy.
|
||||
if ( ! $intended ) {
|
||||
if ( ! $intended_strategy ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -900,16 +900,16 @@ JS;
|
||||
* If the intended strategy is 'defer', limit the initial list of eligible
|
||||
* strategies, since 'async' can fallback to 'defer', but not vice-versa.
|
||||
*/
|
||||
$initial = ( 'defer' === $intended ) ? array( 'defer' ) : null;
|
||||
$initial_strategy = ( 'defer' === $intended_strategy ) ? array( 'defer' ) : null;
|
||||
|
||||
$eligible = $this->filter_eligible_strategies( $handle, $initial );
|
||||
$eligible_strategies = $this->filter_eligible_strategies( $handle, $initial_strategy );
|
||||
|
||||
// Return early once we know the eligible strategy is blocking.
|
||||
if ( empty( $eligible ) ) {
|
||||
if ( empty( $eligible_strategies ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return in_array( 'async', $eligible, true ) ? 'async' : 'defer';
|
||||
return in_array( 'async', $eligible_strategies, true ) ? 'async' : 'defer';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -917,20 +917,20 @@ JS;
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @param string $handle The script handle.
|
||||
* @param string[]|null $eligible Optional. The list of strategies to filter. Default null.
|
||||
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
|
||||
* @param string $handle The script handle.
|
||||
* @param string[]|null $eligible_strategies Optional. The list of strategies to filter. Default null.
|
||||
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
|
||||
* @return string[] A list of eligible loading strategies that could be used.
|
||||
*/
|
||||
private function filter_eligible_strategies( $handle, $eligible = null, $checked = array() ) {
|
||||
private function filter_eligible_strategies( $handle, $eligible_strategies = null, $checked = array() ) {
|
||||
// If no strategies are being passed, all strategies are eligible.
|
||||
if ( null === $eligible ) {
|
||||
$eligible = $this->delayed_strategies;
|
||||
if ( null === $eligible_strategies ) {
|
||||
$eligible_strategies = $this->delayed_strategies;
|
||||
}
|
||||
|
||||
// If this handle was already checked, return early.
|
||||
if ( isset( $checked[ $handle ] ) ) {
|
||||
return $eligible;
|
||||
return $eligible_strategies;
|
||||
}
|
||||
|
||||
// Mark this handle as checked.
|
||||
@ -938,12 +938,12 @@ JS;
|
||||
|
||||
// If this handle isn't registered, don't filter anything and return.
|
||||
if ( ! isset( $this->registered[ $handle ] ) ) {
|
||||
return $eligible;
|
||||
return $eligible_strategies;
|
||||
}
|
||||
|
||||
// If the handle is not enqueued, don't filter anything and return.
|
||||
if ( ! $this->query( $handle, 'enqueued' ) ) {
|
||||
return $eligible;
|
||||
return $eligible_strategies;
|
||||
}
|
||||
|
||||
$is_alias = (bool) ! $this->registered[ $handle ]->src;
|
||||
@ -961,7 +961,7 @@ JS;
|
||||
|
||||
// If the intended strategy is 'defer', filter out 'async'.
|
||||
if ( 'defer' === $intended_strategy ) {
|
||||
$eligible = array( 'defer' );
|
||||
$eligible_strategies = array( 'defer' );
|
||||
}
|
||||
|
||||
$dependents = $this->get_dependents( $handle );
|
||||
@ -969,14 +969,14 @@ JS;
|
||||
// Recursively filter eligible strategies for dependents.
|
||||
foreach ( $dependents as $dependent ) {
|
||||
// Bail early once we know the eligible strategy is blocking.
|
||||
if ( empty( $eligible ) ) {
|
||||
if ( empty( $eligible_strategies ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$eligible = $this->filter_eligible_strategies( $dependent, $eligible, $checked );
|
||||
$eligible_strategies = $this->filter_eligible_strategies( $dependent, $eligible_strategies, $checked );
|
||||
}
|
||||
|
||||
return $eligible;
|
||||
return $eligible_strategies;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,14 +165,14 @@ class WP_Styles extends WP_Dependencies {
|
||||
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];
|
||||
}
|
||||
|
||||
$src = $obj->src;
|
||||
$cond_before = '';
|
||||
$cond_after = '';
|
||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||
$src = $obj->src;
|
||||
$ie_conditional_prefix = '';
|
||||
$ie_conditional_suffix = '';
|
||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||
|
||||
if ( $conditional ) {
|
||||
$cond_before = "<!--[if {$conditional}]>\n";
|
||||
$cond_after = "<![endif]-->\n";
|
||||
$ie_conditional_prefix = "<!--[if {$conditional}]>\n";
|
||||
$ie_conditional_suffix = "<![endif]-->\n";
|
||||
}
|
||||
|
||||
$inline_style = $this->print_inline_style( $handle, false );
|
||||
@ -279,17 +279,17 @@ class WP_Styles extends WP_Dependencies {
|
||||
}
|
||||
|
||||
if ( $this->do_concat ) {
|
||||
$this->print_html .= $cond_before;
|
||||
$this->print_html .= $ie_conditional_prefix;
|
||||
$this->print_html .= $tag;
|
||||
if ( $inline_style_tag ) {
|
||||
$this->print_html .= $inline_style_tag;
|
||||
}
|
||||
$this->print_html .= $cond_after;
|
||||
$this->print_html .= $ie_conditional_suffix;
|
||||
} else {
|
||||
echo $cond_before;
|
||||
echo $ie_conditional_prefix;
|
||||
echo $tag;
|
||||
$this->print_inline_style( $handle );
|
||||
echo $cond_after;
|
||||
echo $ie_conditional_suffix;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -368,7 +368,7 @@ class WP_Styles extends WP_Dependencies {
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public function all_deps( $handles, $recursion = false, $group = false ) {
|
||||
$r = parent::all_deps( $handles, $recursion, $group );
|
||||
$result = parent::all_deps( $handles, $recursion, $group );
|
||||
if ( ! $recursion ) {
|
||||
/**
|
||||
* Filters the array of enqueued styles before processing for output.
|
||||
@ -379,7 +379,7 @@ class WP_Styles extends WP_Dependencies {
|
||||
*/
|
||||
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
||||
}
|
||||
return $r;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.7-alpha-58877';
|
||||
$wp_version = '6.7-alpha-58878';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user