WP_Dependencies::all_deps() WordPress Method

The WP_Dependencies::all_deps() method is used to retrieve all dependencies for a particular script. This is useful for debugging purposes, or for displaying the full list of dependencies for a particular script.

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

Determines dependencies.


Description

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


Top ↑

Parameters

$handles

(string|string[])(Required)Item handle (string) or item handles (array of strings).

$recursion

(bool)(Optional) Internal flag that function is calling itself.

Default value: false

$group

(int|false)(Optional) Group level: level (int), no group (false).

Default value: false


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

Source

File: wp-includes/class.wp-dependencies.php

	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;
	}


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.