WP_Scripts::get_highest_fetchpriority_with_dependents( string $handle, array $checked = array(), array $stored_results = array() ): string|null
- Since
- 6.9.0
- Source
wp-includes/class-wp-scripts.php:1152
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$handlestring- Script module ID.
$checkedarrayoptional- Default:
array() $stored_resultsarrayoptional- Default:
array()
Return value
string|null- Highest fetch priority for the script and its dependents.
Performance profile
How much work a call to WP_Scripts::get_highest_fetchpriority_with_dependents() 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–65
- 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::get_highest_fetchpriority_with_dependents() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | none |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && !->query() | 15 | ->query() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && ->query() && $highest_priority_index === false | 40–41 | ->query(), ->get_data(), ->is_valid_fetchpriority(), array_search() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && ->query() && $highest_priority_index !== false | 45–47 | ->query(), ->get_data(), ->is_valid_fetchpriority(), array_search(), ->get_dependents() |
!isset($stored_results[$handle]) && !isset($checked[$handle]) && ->query() && !->get_dependents() && is_string($dependent_priority) | 64–65 | ->query(), ->get_data(), ->is_valid_fetchpriority(), array_search(), ->get_dependents(), ->get_highest_fetchpriority_with_dependents(), array_search() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 70 | 8–65 | 9 | |
| 8.5 | 70 | 8–65 | 9 | |
| 8.4 | 70 | 8–65 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 73 | 8–68 | 9 | |
| 8.2 | 73 | 8–68 | 9 | |
| 8.1 | 73 | 8–68 | 9 | |
| 7.4 | 73 | 8–68 | 9 |
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::is_valid_fetchpriority()Checks if the provided fetchpriority is valid.
- WP_Scripts::get_dependents()Gets all dependents of a script.
- WP_Scripts::get_highest_fetchpriority_with_dependents()Gets the highest fetch priority for a given script and all of its dependent scripts.
Used by · 2
- WP_Scripts::do_item()Processes a script dependency.
- WP_Scripts::get_highest_fetchpriority_with_dependents()Gets the highest fetch priority for a given script and all of its dependent scripts.
Source code
private function get_highest_fetchpriority_with_dependents( string $handle, array $checked = array(), array &$stored_results = array() ): ?string { if ( isset( $stored_results[ $handle ] ) ) { return $stored_results[ $handle ]; } // If there is a recursive dependency, return early. if ( isset( $checked[ $handle ] ) ) { return null; } // Mark this handle as checked to guard against infinite recursion. $checked[ $handle ] = true; // Abort if the script is not enqueued or a dependency of an enqueued script. if ( ! $this->query( $handle, 'enqueued' ) ) { return null; } $fetchpriority = $this->get_data( $handle, 'fetchpriority' ); if ( ! $this->is_valid_fetchpriority( $fetchpriority ) ) { $fetchpriority = 'auto'; } static $priorities = array( 'low', 'auto', 'high', ); $high_priority_index = count( $priorities ) - 1; $highest_priority_index = (int) array_search( $fetchpriority, $priorities, true ); if ( $highest_priority_index !== $high_priority_index ) { foreach ( $this->get_dependents( $handle ) as $dependent_handle ) { $dependent_priority = $this->get_highest_fetchpriority_with_dependents( $dependent_handle, $checked, $stored_results ); if ( is_string( $dependent_priority ) ) { $highest_priority_index = max( $highest_priority_index, (int) array_search( $dependent_priority, $priorities, true ) ); if ( $highest_priority_index === $high_priority_index ) { break; } } } } $stored_results[ $handle ] = $priorities[ $highest_priority_index ]; return $priorities[ $highest_priority_index ]; }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About 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.