WP_Scripts::filter_eligible_strategies( string $handle, string[]|null $eligible_strategies = null, $checked = array(), array $stored_results = array() ): string[]
- Since
- 6.3.0
- Source
wp-includes/class-wp-scripts.php:1079
Compatibility
- WordPress
- since 6.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$handlestring- The script handle.
$eligible_strategiesstring[]|nulloptional- The list of strategies to filter. Default null.Default:
null $checkedoptional- Default:
array() $stored_resultsarrayoptional- Default:
array()
Return value
string[]- A list of eligible loading strategies that could be used.
Performance profile
How much work a call to WP_Scripts::filter_eligible_strategies() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 8–51
- Plugin surface
- None
- Called by
- 2
Reaches the database via ->query().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 70.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
->query()called directly
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Scripts::filter_eligible_strategies() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–17 | none |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && isset($handle) && !->query() | 21–22 | ->query() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && isset($handle) && ->query() && $value && empty($intended_strategy) | 33–34 | ->query(), ->get_data() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && isset($handle) && ->query() && ->has_inline_script() | 36–39 | ->query(), ->get_data(), ->has_inline_script() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && isset($handle) && ->query() && !->has_inline_script() | 46–51 | ->query(), ->get_data(), ->has_inline_script(), ->get_dependents() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 70 instructions, 8–51 executed per call, 12 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- WP_Scripts::query()
- WP_Scripts::get_data()
- WP_Scripts::has_inline_script()Gets data for inline scripts registered for a specific handle.
- WP_Scripts::get_dependents()Gets all dependents of a script.
- WP_Scripts::filter_eligible_strategies()Filter the list of eligible loading strategies for a script.
Used by · 2
- WP_Scripts::filter_eligible_strategies()Filter the list of eligible loading strategies for a script.
- WP_Scripts::get_eligible_loading_strategy()Gets the best eligible loading strategy for a script.
Source code
private function filter_eligible_strategies( $handle, $eligible_strategies = null, $checked = array(), array &$stored_results = array() ) { if ( isset( $stored_results[ $handle ] ) ) { return $stored_results[ $handle ]; } // If no strategies are being passed, all strategies are eligible. if ( null === $eligible_strategies ) { $eligible_strategies = $this->delayed_strategies; } // If this handle was already checked, return early. if ( isset( $checked[ $handle ] ) ) { return $eligible_strategies; } // Mark this handle as checked. $checked[ $handle ] = true; // If this handle isn't registered, don't filter anything and return. if ( ! isset( $this->registered[ $handle ] ) ) { return $eligible_strategies; } // If the handle is not enqueued, don't filter anything and return. if ( ! $this->query( $handle, 'enqueued' ) ) { return $eligible_strategies; } $is_alias = (bool) ! $this->registered[ $handle ]->src; $intended_strategy = $this->get_data( $handle, 'strategy' ); // For non-alias handles, an empty intended strategy filters all strategies. if ( ! $is_alias && empty( $intended_strategy ) ) { return array(); } // Handles with inline scripts attached in the 'after' position cannot be delayed. if ( $this->has_inline_script( $handle, 'after' ) ) { return array(); } // If the intended strategy is 'defer', filter out 'async'. if ( 'defer' === $intended_strategy ) { $eligible_strategies = array( 'defer' ); } $dependents = $this->get_dependents( $handle ); // Recursively filter eligible strategies for dependents. foreach ( $dependents as $dependent ) { // Bail early once we know the eligible strategy is blocking. if ( empty( $eligible_strategies ) ) { return array(); } $eligible_strategies = $this->filter_eligible_strategies( $dependent, $eligible_strategies, $checked, $stored_results ); } $stored_results[ $handle ] = $eligible_strategies; return $eligible_strategies; }Changelog
Introduced in 6.3.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$stored_results added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-scripts.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.