Automattic\WooCommerce\Blocks
DependencyDetection::build_script_registry
Build a registry of all enqueued scripts with their URLs and dependencies.
Method of the class: DependencyDetection{}
No Hooks.
Returns
array<string,. array{handle: string, deps: array<string>}>
Usage
// private - for code of main (parent) class only $result = $this->build_script_registry(): array;
DependencyDetection::build_script_registry() DependencyDetection::build script registry code WC 11.1.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;
}