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
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 10.7.0
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;
}
if ( ! preg_match( '|^(https?:)?//|', $src ) ) {
// Relative URL - make it absolute.
$src = $wp_scripts->base_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;
}