WP_Script_Modules::get_recursive_dependents( string $id ): string[]

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use WP_Scripts::get_dependents() instead.

Gets all recursive dependents of a script module.

Description

See also

Parameters

$idstringrequired
The script ID.

Return

string[] Script module IDs.

Source

private function get_recursive_dependents( string $id ): array {
	$dependents = array();
	$id_queue   = array( $id );
	$processed  = array();

	while ( ! empty( $id_queue ) ) {
		$current_id = array_shift( $id_queue );

		// Skip unregistered or already-processed script modules.
		if ( ! isset( $this->registered[ $current_id ] ) || isset( $processed[ $current_id ] ) ) {
			continue;
		}

		// Mark as processed to guard against infinite loops from circular dependencies.
		$processed[ $current_id ] = true;

		// Find the direct dependents of the current script.
		foreach ( $this->get_dependents( $current_id ) as $dependent_id ) {
			// Only add the dependent if we haven't found it before.
			if ( ! isset( $dependents[ $dependent_id ] ) ) {
				$dependents[ $dependent_id ] = true;

				// Add dependency to the queue.
				$id_queue[] = $dependent_id;
			}
		}
	}

	return array_keys( $dependents );
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.