wppaste
WordPress

WP_Dependencies::all_deps( string|string[] $handles, bool $recursion = false, int|false $group = false ): bool

Since
2.1.0, 2.6.0, 2.8.0
Source
wp-includes/class-wp-dependencies.php:193
Determines dependencies.

Description

Recursively builds an array of items to process taking dependencies into account. Does NOT catch infinite loops.

Compatibility

WordPress
since 2.8.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

$handlesstring|string[]
Item handle (string) or item handles (array of strings).
$recursionbooloptional
Internal flag that function is calling itself.
Default false.Default: false
$groupint|falseoptional
Group level: level (int), no group (false).
Default false.Default: false

Return value

bool
True on success, false on failure.

Performance profile

How much work a call to WP_Dependencies::all_deps() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
7–87

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_Dependencies::all_deps()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 7 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Dependencies::all_deps() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always7–10none
!$handles && !$handle46–60explode(), ->set_group()
!$handles && !$handle && isset($handle)60–68explode(), ->set_group(), ->all_deps()
!$handles && !$handle && isset($handle)64–72explode(), ->set_group(), array_keys(), array_diff()
!$handles && !$handle && isset($handle)68–75explode(), ->set_group(), ->get_dependency_warning_message(), _doing_it_wrong()
!$handles && !$handle && isset($handle)78–80explode(), ->set_group(), array_keys(), array_diff(), ->all_deps()
!$handles && !$handle && isset($handle)86–87explode(), ->set_group(), array_keys(), array_diff(), ->get_dependency_warning_message(), _doing_it_wrong()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1177–8717
8.51177–8717
8.41177–87179 fewer instructions than PHP 8.3
8.31267–9617
8.21267–9617
8.11267–96171 fewer instruction than PHP 7.4
7.41277–9617

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 · 4

Used by · 4

Source code

	public function all_deps( $handles, $recursion = false, $group = false ) {		$handles = (array) $handles;		if ( ! $handles ) {			return false;		} 		foreach ( $handles as $handle ) {			$handle_parts = explode( '?', $handle );			$handle       = $handle_parts[0];			$queued       = in_array( $handle, $this->to_do, true ); 			if ( in_array( $handle, $this->done, true ) ) { // Already done.				continue;			} 			$moved     = $this->set_group( $handle, $recursion, $group );			$new_group = $this->groups[ $handle ]; 			if ( $queued && ! $moved ) { // Already queued and in the right group.				continue;			} 			$keep_going           = true;			$missing_dependencies = array();			if ( isset( $this->registered[ $handle ] ) && count( $this->registered[ $handle ]->deps ) > 0 ) {				$missing_dependencies = array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) );			}			if ( ! isset( $this->registered[ $handle ] ) ) {				$keep_going = false; // Item doesn't exist.			} elseif ( count( $missing_dependencies ) > 0 ) {				if ( ! in_array( $handle, $this->dependencies_with_missing_dependencies, true ) ) {					_doing_it_wrong(						get_class( $this ) . '::add',						$this->get_dependency_warning_message( $handle, $missing_dependencies ),						'6.9.1'					);					$this->dependencies_with_missing_dependencies[] = $handle;				}				$keep_going = false; // Item requires dependencies that don't exist.			} elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) {				$keep_going = false; // Item requires dependencies that don't exist.			} 			if ( ! $keep_going ) { // Either item or its dependencies don't exist.				if ( $recursion ) {					return false; // Abort this branch.				} else {					continue; // We're at the top level. Move on to the next one.				}			} 			if ( $queued ) { // Already grabbed it and its dependencies.				continue;			} 			if ( isset( $handle_parts[1] ) ) {				$this->args[ $handle ] = $handle_parts[1];			} 			$this->to_do[] = $handle;		} 		return true;	}

Changelog

Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

2.8.0
Added the $group parameter.from the docblock
2.6.0
Moved from WP_Scripts.from the docblock
2.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-dependencies.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.