wppaste
WordPress

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
Gets the highest fetch priority for a given script and all of its dependent scripts.

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

Reaches the database via ->query().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
8–65

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 70.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

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.

WhenInstructionsCalls it makes
always8none
!isset($stored_results[$handle]) && !isset($checked[$handle]) && !->query()15->query()
!isset($stored_results[$handle]) && !isset($checked[$handle]) && ->query() && $highest_priority_index === false40–41->query(), ->get_data(), ->is_valid_fetchpriority(), array_search()
!isset($stored_results[$handle]) && !isset($checked[$handle]) && ->query() && $highest_priority_index !== false45–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

PHPCompiledExecutedBranchesNotes
8.6-dev708–659
8.5708–659
8.4708–6593 fewer instructions than PHP 8.3
8.3738–689
8.2738–689
8.1738–689
7.4738–689

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

Used by · 2

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.

  1. 6.9.7
  2. 7.0.4
  3. 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.