WP_Script_Modules::get_dependenciesprivateWP 6.5.0

Retrieves all the dependencies for the given script module identifiers, filtered by import types.

It will consolidate an array containing a set of unique dependencies based on the requested import types: 'static', 'dynamic', or both. This method is recursive and also retrieves dependencies of the dependencies.

Method of the class: WP_Script_Modules{}

No Hooks.

Returns

Array. array<string, mixed>> List of dependencies, keyed by script module identifier.

Usage

$result = WP_Script_Modules::get_dependencies( $ids, $import_types, fooo ) ): array;
$ids(string[]) (required)
The identifiers of the script modules for which to gather dependencies.
$import_types(string[])
Import types of dependencies to retrieve: 'static', 'dynamic', or both.
Default: both
fooo )(required)
.

Changelog

Since 6.5.0 Introduced.

WP_Script_Modules::get_dependencies() code WP 7.0

private function get_dependencies( array $ids, array $import_types = array( 'static', 'dynamic' ) ): array {
	$all_dependencies = array();
	$id_queue         = $ids;

	while ( ! empty( $id_queue ) ) {
		$id = array_shift( $id_queue );
		if ( ! isset( $this->registered[ $id ] ) ) {
			continue;
		}

		foreach ( $this->registered[ $id ]['dependencies'] as $dependency ) {
			if (
				! isset( $all_dependencies[ $dependency['id'] ] ) &&
				in_array( $dependency['import'], $import_types, true ) &&
				isset( $this->registered[ $dependency['id'] ] )
			) {
				$all_dependencies[ $dependency['id'] ] = $this->registered[ $dependency['id'] ];

				// Add this dependency to the list to get dependencies for.
				$id_queue[] = $dependency['id'];
			}
		}
	}

	return $all_dependencies;
}