Automattic\WooCommerce\Blocks
DependencyDetection::is_woocommerce_script
Check if a script URL belongs to WooCommerce core.
Checks if the script is loaded from the WooCommerce core plugin directory, not from third-party extensions that may use similar handle naming.
Метод класса: DependencyDetection{}
Хуков нет.
Возвращает
true|false.
Использование
// private - только в коде основоного (родительского) класса $result = $this->is_woocommerce_script( $url ): bool;
- $url(строка) (обязательный)
- Script URL.
Код DependencyDetection::is_woocommerce_script() DependencyDetection::is woocommerce script WC 11.0.1
private function is_woocommerce_script( string $url ): bool {
// Get the WooCommerce plugin URL (accounts for custom plugin directories).
$wc_plugin_url = \plugins_url( '/', WC_PLUGIN_FILE );
// Check if the URL starts with the WooCommerce plugin URL and is in a known subdirectory.
if ( strpos( $url, $wc_plugin_url ) !== 0 ) {
return false;
}
// Get the path after the WooCommerce plugin URL.
$relative_path = substr( $url, strlen( $wc_plugin_url ) );
// Check if it's in one of the known WooCommerce asset directories.
return (bool) preg_match( '#^(client|assets|build|vendor)/#', $relative_path );
}