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:180
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
- Scaling
- Scales with input
- Instructions
- 7–71
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
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 89.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
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_Dependencies::all_deps() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–10 | none |
!$handles && !$handle | 42–49 | explode(), ->set_group() |
!$handles && !$handle && isset($handle) | 57–59 | explode(), ->set_group(), ->all_deps() |
!$handles && !$handle && isset($handle) | 58–61 | explode(), ->set_group(), array_keys(), array_diff() |
!$handles && !$handle && isset($handle) && !array_diff() | 69–71 | explode(), ->set_group(), array_keys(), array_diff(), ->all_deps() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 89 | 7–71 | 15 | |
| 8.5 | 89 | 7–71 | 15 | |
| 8.4 | 89 | 7–71 | 15 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 95 | 7–77 | 15 | |
| 8.2 | 95 | 7–77 | 15 | |
| 8.1 | 95 | 7–77 | 15 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 96 | 7–78 | 15 |
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 · 2
- WP_Dependencies::set_group()Set item group, unless already in a lower group.
- WP_Dependencies::all_deps()Determines dependencies.
Used by · 4
- WP_Dependencies::all_deps()Determines dependencies.
- WP_Dependencies::do_items()Processes the items and dependencies.
- WP_Scripts::all_deps()Determines script dependencies.
- WP_Styles::all_deps()Determines style dependencies.
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; if ( ! isset( $this->registered[ $handle ] ) ) { $keep_going = false; // Item doesn't exist. } elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) { $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.
Signature, return type and hooks compared across 5 parsed releases.
$group parameter.from the docblockWP_Scripts.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.