mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 09:07:59 +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
@ -292,8 +292,8 @@ class WP_Scripts extends WP_Dependencies {
|
|||||||
$src = $obj->src;
|
$src = $obj->src;
|
||||||
$strategy = $this->get_eligible_loading_strategy( $handle );
|
$strategy = $this->get_eligible_loading_strategy( $handle );
|
||||||
$intended_strategy = (string) $this->get_data( $handle, 'strategy' );
|
$intended_strategy = (string) $this->get_data( $handle, 'strategy' );
|
||||||
$cond_before = '';
|
$ie_conditional_prefix = '';
|
||||||
$cond_after = '';
|
$ie_conditional_suffix = '';
|
||||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||||
|
|
||||||
if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {
|
if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {
|
||||||
@ -320,15 +320,15 @@ class WP_Scripts extends WP_Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $conditional ) {
|
if ( $conditional ) {
|
||||||
$cond_before = "<!--[if {$conditional}]>\n";
|
$ie_conditional_prefix = "<!--[if {$conditional}]>\n";
|
||||||
$cond_after = "<![endif]-->\n";
|
$ie_conditional_suffix = "<![endif]-->\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$before_script = $this->get_inline_script_tag( $handle, 'before' );
|
$before_script = $this->get_inline_script_tag( $handle, 'before' );
|
||||||
$after_script = $this->get_inline_script_tag( $handle, 'after' );
|
$after_script = $this->get_inline_script_tag( $handle, 'after' );
|
||||||
|
|
||||||
if ( $before_script || $after_script ) {
|
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 {
|
} else {
|
||||||
$inline_script_tag = '';
|
$inline_script_tag = '';
|
||||||
}
|
}
|
||||||
@ -353,10 +353,10 @@ class WP_Scripts extends WP_Dependencies {
|
|||||||
* @param string $src Script loader source path.
|
* @param string $src Script loader source path.
|
||||||
* @param string $handle Script handle.
|
* @param string $handle Script handle.
|
||||||
*/
|
*/
|
||||||
$srce = apply_filters( 'script_loader_src', $src, $handle );
|
$filtered_src = apply_filters( 'script_loader_src', $src, $handle );
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$this->in_default_dir( $srce )
|
$this->in_default_dir( $filtered_src )
|
||||||
&& ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) )
|
&& ( $before_script || $after_script || $translations_stop_concat || $this->is_delayed_strategy( $strategy ) )
|
||||||
) {
|
) {
|
||||||
$this->do_concat = false;
|
$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.
|
// Have to print the so-far concatenated scripts right away to maintain the right order.
|
||||||
_print_scripts();
|
_print_scripts();
|
||||||
$this->reset();
|
$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->print_code .= $this->print_extra_script( $handle, false );
|
||||||
$this->concat .= "$handle,";
|
$this->concat .= "$handle,";
|
||||||
$this->concat_version .= "$handle$ver";
|
$this->concat_version .= "$handle$ver";
|
||||||
@ -378,13 +378,13 @@ class WP_Scripts extends WP_Dependencies {
|
|||||||
$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
|
$has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
|
||||||
|
|
||||||
if ( $has_conditional_data ) {
|
if ( $has_conditional_data ) {
|
||||||
echo $cond_before;
|
echo $ie_conditional_prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->print_extra_script( $handle );
|
$this->print_extra_script( $handle );
|
||||||
|
|
||||||
if ( $has_conditional_data ) {
|
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.
|
// 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 ) {
|
if ( $intended_strategy ) {
|
||||||
$attr['data-wp-strategy'] = $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 .= 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.
|
* 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 ) {
|
public function set_group( $handle, $recursion, $group = false ) {
|
||||||
if ( isset( $this->registered[ $handle ]->args ) && 1 === $this->registered[ $handle ]->args ) {
|
if ( isset( $this->registered[ $handle ]->args ) && 1 === $this->registered[ $handle ]->args ) {
|
||||||
$grp = 1;
|
$calculated_group = 1;
|
||||||
} else {
|
} else {
|
||||||
$grp = (int) $this->get_data( $handle, 'group' );
|
$calculated_group = (int) $this->get_data( $handle, 'group' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( false !== $group && $grp > $group ) {
|
if ( false !== $group && $calculated_group > $group ) {
|
||||||
$grp = $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.
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
public function all_deps( $handles, $recursion = false, $group = false ) {
|
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 ) {
|
if ( ! $recursion ) {
|
||||||
/**
|
/**
|
||||||
* Filters the list of script dependencies left to print.
|
* 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 );
|
$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.
|
* @return string The best eligible loading strategy.
|
||||||
*/
|
*/
|
||||||
private function get_eligible_loading_strategy( $handle ) {
|
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.
|
// Bail early if there is no intended strategy.
|
||||||
if ( ! $intended ) {
|
if ( ! $intended_strategy ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,16 +900,16 @@ JS;
|
|||||||
* If the intended strategy is 'defer', limit the initial list of eligible
|
* If the intended strategy is 'defer', limit the initial list of eligible
|
||||||
* strategies, since 'async' can fallback to 'defer', but not vice-versa.
|
* 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.
|
// Return early once we know the eligible strategy is blocking.
|
||||||
if ( empty( $eligible ) ) {
|
if ( empty( $eligible_strategies ) ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return in_array( 'async', $eligible, true ) ? 'async' : 'defer';
|
return in_array( 'async', $eligible_strategies, true ) ? 'async' : 'defer';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -918,19 +918,19 @@ JS;
|
|||||||
* @since 6.3.0
|
* @since 6.3.0
|
||||||
*
|
*
|
||||||
* @param string $handle The script handle.
|
* @param string $handle The script handle.
|
||||||
* @param string[]|null $eligible Optional. The list of strategies to filter. Default null.
|
* @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.
|
* @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.
|
* @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 no strategies are being passed, all strategies are eligible.
|
||||||
if ( null === $eligible ) {
|
if ( null === $eligible_strategies ) {
|
||||||
$eligible = $this->delayed_strategies;
|
$eligible_strategies = $this->delayed_strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this handle was already checked, return early.
|
// If this handle was already checked, return early.
|
||||||
if ( isset( $checked[ $handle ] ) ) {
|
if ( isset( $checked[ $handle ] ) ) {
|
||||||
return $eligible;
|
return $eligible_strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark this handle as checked.
|
// Mark this handle as checked.
|
||||||
@ -938,12 +938,12 @@ JS;
|
|||||||
|
|
||||||
// If this handle isn't registered, don't filter anything and return.
|
// If this handle isn't registered, don't filter anything and return.
|
||||||
if ( ! isset( $this->registered[ $handle ] ) ) {
|
if ( ! isset( $this->registered[ $handle ] ) ) {
|
||||||
return $eligible;
|
return $eligible_strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the handle is not enqueued, don't filter anything and return.
|
// If the handle is not enqueued, don't filter anything and return.
|
||||||
if ( ! $this->query( $handle, 'enqueued' ) ) {
|
if ( ! $this->query( $handle, 'enqueued' ) ) {
|
||||||
return $eligible;
|
return $eligible_strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_alias = (bool) ! $this->registered[ $handle ]->src;
|
$is_alias = (bool) ! $this->registered[ $handle ]->src;
|
||||||
@ -961,7 +961,7 @@ JS;
|
|||||||
|
|
||||||
// If the intended strategy is 'defer', filter out 'async'.
|
// If the intended strategy is 'defer', filter out 'async'.
|
||||||
if ( 'defer' === $intended_strategy ) {
|
if ( 'defer' === $intended_strategy ) {
|
||||||
$eligible = array( 'defer' );
|
$eligible_strategies = array( 'defer' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$dependents = $this->get_dependents( $handle );
|
$dependents = $this->get_dependents( $handle );
|
||||||
@ -969,14 +969,14 @@ JS;
|
|||||||
// Recursively filter eligible strategies for dependents.
|
// Recursively filter eligible strategies for dependents.
|
||||||
foreach ( $dependents as $dependent ) {
|
foreach ( $dependents as $dependent ) {
|
||||||
// Bail early once we know the eligible strategy is blocking.
|
// Bail early once we know the eligible strategy is blocking.
|
||||||
if ( empty( $eligible ) ) {
|
if ( empty( $eligible_strategies ) ) {
|
||||||
return array();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,13 +166,13 @@ class WP_Styles extends WP_Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$src = $obj->src;
|
$src = $obj->src;
|
||||||
$cond_before = '';
|
$ie_conditional_prefix = '';
|
||||||
$cond_after = '';
|
$ie_conditional_suffix = '';
|
||||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||||
|
|
||||||
if ( $conditional ) {
|
if ( $conditional ) {
|
||||||
$cond_before = "<!--[if {$conditional}]>\n";
|
$ie_conditional_prefix = "<!--[if {$conditional}]>\n";
|
||||||
$cond_after = "<![endif]-->\n";
|
$ie_conditional_suffix = "<![endif]-->\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$inline_style = $this->print_inline_style( $handle, false );
|
$inline_style = $this->print_inline_style( $handle, false );
|
||||||
@ -279,17 +279,17 @@ class WP_Styles extends WP_Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->do_concat ) {
|
if ( $this->do_concat ) {
|
||||||
$this->print_html .= $cond_before;
|
$this->print_html .= $ie_conditional_prefix;
|
||||||
$this->print_html .= $tag;
|
$this->print_html .= $tag;
|
||||||
if ( $inline_style_tag ) {
|
if ( $inline_style_tag ) {
|
||||||
$this->print_html .= $inline_style_tag;
|
$this->print_html .= $inline_style_tag;
|
||||||
}
|
}
|
||||||
$this->print_html .= $cond_after;
|
$this->print_html .= $ie_conditional_suffix;
|
||||||
} else {
|
} else {
|
||||||
echo $cond_before;
|
echo $ie_conditional_prefix;
|
||||||
echo $tag;
|
echo $tag;
|
||||||
$this->print_inline_style( $handle );
|
$this->print_inline_style( $handle );
|
||||||
echo $cond_after;
|
echo $ie_conditional_suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -368,7 +368,7 @@ class WP_Styles extends WP_Dependencies {
|
|||||||
* @return bool True on success, false on failure.
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
public function all_deps( $handles, $recursion = false, $group = false ) {
|
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 ) {
|
if ( ! $recursion ) {
|
||||||
/**
|
/**
|
||||||
* Filters the array of enqueued styles before processing for output.
|
* 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 );
|
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
||||||
}
|
}
|
||||||
return $r;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user