Automattic\WooCommerce\Blocks

DependencyDetection::build_script_registry │ private │ WC 1.0

Build a registry of all enqueued scripts with their URLs and dependencies.

Метод класса: DependencyDetection{}

Хуков нет.

Возвращает

array<string,. array{handle: string, deps: array<string>}>

Использование

// private - только в коде основоного (родительского) класса
$result = $this->build_script_registry(): array;

Код DependencyDetection::build_script_registry() WC 11.2.2

private function build_script_registry(): array {
	$wp_scripts = wp_scripts();
	$registry   = array();

	foreach ( $wp_scripts->registered as $handle => $script ) {
		// Skip scripts without a source URL.
		if ( empty( $script->src ) ) {
			continue;
		}

		// Get the full URL.
		$src = $script->src;
		if ( ! is_string( $src ) ) {
			// Skip malformed src.
			continue;
		}
		// Resolve relative URLs to absolute the same way WordPress core does.
		$src = Utils::get_absolute_script_url( $src );

		// Skip WooCommerce's own scripts - we don't need to check those.
		if ( $this->is_woocommerce_script( $src ) ) {
			continue;
		}

		// Skip WordPress core scripts - they won't use wc.* globals.
		if ( $this->is_wordpress_core_script( $src ) ) {
			continue;
		}

		// Normalize the URL for consistent matching.
		$src = $this->normalize_url( $src );

		$registry[ $src ] = array(
			'handle' => $handle,
			'deps'   => $this->get_all_dependencies( $script->deps ),
		);
	}

	return $registry;
}