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2.0-rc.1 3.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Blocks / DependencyDetection.php
woocommerce / src / Blocks Last commit date
AI 1 year ago AIContent 1 year ago Assets 3 days ago BlockTypes 3 days ago Domain 3 days ago Images 1 year ago Integrations 2 years ago Patterns 3 days ago Payments 5 months ago Registry 2 years ago SharedStores 2 months ago Shipping 3 days ago Templates 3 days ago Utils 3 days ago Assets.php 2 years ago AssetsController.php 3 days ago BlockPatterns.php 3 days ago BlockTemplatesController.php 7 months ago BlockTemplatesRegistry.php 10 months ago BlockTypesController.php 1 month ago DependencyDetection.php 3 days ago InboxNotifications.php 2 years ago Installer.php 2 months ago Library.php 2 years ago Options.php 2 years ago Package.php 1 year ago QueryFilters.php 3 days ago TemplateOptions.php 1 year ago
DependencyDetection.php
357 lines
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Automattic\WooCommerce\Blocks;
5
6 use Automattic\WooCommerce\Blocks\Utils\Utils;
7 use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
8
9 /**
10 * DependencyDetection class.
11 *
12 * Provides runtime detection of extensions that use Blocks related WooCommerce globals
13 * (window.wc.*) without properly declaring their PHP script dependencies.
14 *
15 * This runs by default to warn developers about missing dependencies.
16 *
17 * @since 10.5.0
18 * @internal
19 */
20 final class DependencyDetection {
21
22 /**
23 * WooCommerce blocks that use the tracked globals.
24 *
25 * Detection script only runs on pages containing these blocks.
26 *
27 * @var array<string>
28 */
29 private const TRACKED_BLOCKS = array(
30 'woocommerce/checkout',
31 'woocommerce/cart',
32 'woocommerce/mini-cart',
33 );
34
35 /**
36 * Maps window.wc.* property names to their required script handles.
37 *
38 * This is the source of truth for both PHP and JS dependency detection.
39 * Based on wcDepMap and wcHandleMap in client/blocks/bin/webpack-helpers.js.
40 *
41 * @var array<string, string>
42 */
43 private const WC_GLOBAL_EXPORTS = array(
44 'wcBlocksRegistry' => 'wc-blocks-registry',
45 'wcSettings' => 'wc-settings',
46 'wcBlocksData' => 'wc-blocks-data-store',
47 'data' => 'wc-store-data',
48 'wcBlocksSharedContext' => 'wc-blocks-shared-context',
49 'wcBlocksSharedHocs' => 'wc-blocks-shared-hocs',
50 'priceFormat' => 'wc-price-format',
51 'blocksCheckout' => 'wc-blocks-checkout',
52 'blocksCheckoutEvents' => 'wc-blocks-checkout-events',
53 'blocksComponents' => 'wc-blocks-components',
54 'wcTypes' => 'wc-types',
55 'sanitize' => 'wc-sanitize',
56 );
57
58 /**
59 * Whether the proxy script was output.
60 *
61 * Used to ensure we only output the registry if the proxy was set up.
62 *
63 * @var bool
64 */
65 private bool $proxy_output = false;
66
67 /**
68 * Constructor.
69 */
70 public function __construct() {
71 $this->init();
72 }
73
74 /**
75 * Initialize hooks.
76 *
77 * @since 10.5.0
78 */
79 public function init(): void {
80 // Only run when debugging is enabled.
81 if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
82 return;
83 }
84
85 // Output an early inline script to set up the Proxy before any other scripts run.
86 add_action( 'wp_head', array( $this, 'output_early_proxy_setup' ), 1 );
87 add_action( 'admin_head', array( $this, 'output_early_proxy_setup' ), 1 );
88
89 // Output registry late when all scripts (including IntegrationInterface) are registered.
90 add_action( 'wp_print_footer_scripts', array( $this, 'output_script_registry' ), 1 );
91 add_action( 'admin_print_footer_scripts', array( $this, 'output_script_registry' ), 1 );
92 }
93
94 /**
95 * Output early inline script to set up the Proxy on window.wc.
96 *
97 * This must run before any WooCommerce scripts to intercept access.
98 * The script is loaded from a separate file for better IDE support and testing,
99 * but output inline to ensure correct timing (before any enqueued scripts).
100 *
101 * @since 10.5.0
102 */
103 public function output_early_proxy_setup(): void {
104 // Only run on pages that have the tracked blocks.
105 if ( ! $this->page_has_tracked_blocks() ) {
106 return;
107 }
108
109 // Load from the production assets directory (built by webpack and copied during release build).
110 $script_path = __DIR__ . '/../../assets/client/blocks/dependency-detection.js';
111
112 if ( ! file_exists( $script_path ) ) {
113 return;
114 }
115
116 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file read for inline script output.
117 $script_content = file_get_contents( $script_path );
118
119 if ( ! $script_content ) {
120 return;
121 }
122
123 // Inject the global-to-handle mapping from PHP (source of truth).
124 $mapping_json = \wp_json_encode( self::WC_GLOBAL_EXPORTS );
125 if ( false === $mapping_json ) {
126 return;
127 }
128 $script_content = str_replace(
129 '__WC_GLOBAL_EXPORTS_PLACEHOLDER__',
130 $mapping_json,
131 $script_content
132 );
133
134 // Inject the WooCommerce plugin URL for script origin detection.
135 // This accounts for custom plugin directories (WP_PLUGIN_DIR, WP_CONTENT_DIR).
136 $wc_plugin_url = \plugins_url( '/', WC_PLUGIN_FILE );
137 $script_content = str_replace(
138 '__WC_PLUGIN_URL_PLACEHOLDER__',
139 '"' . esc_js( $wc_plugin_url ) . '"',
140 $script_content
141 );
142
143 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Script content is from a trusted local file, JSON is safely encoded.
144 echo '<script id="wc-dependency-detection">' . $script_content . '</script>' . "\n";
145
146 $this->proxy_output = true;
147 }
148
149 /**
150 * Output the script registry JSON for dependency checking.
151 *
152 * This runs late (wp_print_footer_scripts) to ensure all scripts,
153 * including those registered via IntegrationInterface, are captured.
154 *
155 * @since 10.5.0
156 */
157 public function output_script_registry(): void {
158 // Only output registry if the proxy was set up earlier.
159 // This avoids the duplicate page_has_tracked_blocks() check and ensures
160 // we don't output a registry without a proxy to consume it.
161 if ( ! $this->proxy_output ) {
162 return;
163 }
164
165 // Build the script registry mapping URLs to handles and dependencies.
166 $script_registry = $this->build_script_registry();
167 $registry_json = \wp_json_encode( $script_registry );
168
169 if ( false === $registry_json ) {
170 return;
171 }
172
173 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON is safely encoded by wp_json_encode.
174 echo '<script id="wc-dependency-detection-registry">if(typeof window.wc.wcUpdateDependencyRegistry==="function"){window.wc.wcUpdateDependencyRegistry(' . $registry_json . ');}</script>' . "\n";
175 }
176
177 /**
178 * Build a registry of all enqueued scripts with their URLs and dependencies.
179 *
180 * @return array<string, array{handle: string, deps: array<string>}>
181 */
182 private function build_script_registry(): array {
183 $wp_scripts = wp_scripts();
184 $registry = array();
185
186 foreach ( $wp_scripts->registered as $handle => $script ) {
187 // Skip scripts without a source URL.
188 if ( empty( $script->src ) ) {
189 continue;
190 }
191
192 // Get the full URL.
193 $src = $script->src;
194 if ( ! is_string( $src ) ) {
195 // Skip malformed src.
196 continue;
197 }
198 // Resolve relative URLs to absolute the same way WordPress core does.
199 $src = Utils::get_absolute_script_url( $src );
200
201 // Skip WooCommerce's own scripts - we don't need to check those.
202 if ( $this->is_woocommerce_script( $src ) ) {
203 continue;
204 }
205
206 // Skip WordPress core scripts - they won't use wc.* globals.
207 if ( $this->is_wordpress_core_script( $src ) ) {
208 continue;
209 }
210
211 // Normalize the URL for consistent matching.
212 $src = $this->normalize_url( $src );
213
214 $registry[ $src ] = array(
215 'handle' => $handle,
216 'deps' => $this->get_all_dependencies( $script->deps ),
217 );
218 }
219
220 return $registry;
221 }
222
223 /**
224 * Check if a script URL belongs to WooCommerce core.
225 *
226 * Checks if the script is loaded from the WooCommerce core plugin directory,
227 * not from third-party extensions that may use similar handle naming.
228 *
229 * @param string $url Script URL.
230 * @return bool
231 */
232 private function is_woocommerce_script( string $url ): bool {
233 // Get the WooCommerce plugin URL (accounts for custom plugin directories).
234 $wc_plugin_url = \plugins_url( '/', WC_PLUGIN_FILE );
235
236 // Check if the URL starts with the WooCommerce plugin URL and is in a known subdirectory.
237 if ( strpos( $url, $wc_plugin_url ) !== 0 ) {
238 return false;
239 }
240
241 // Get the path after the WooCommerce plugin URL.
242 $relative_path = substr( $url, strlen( $wc_plugin_url ) );
243
244 // Check if it's in one of the known WooCommerce asset directories.
245 return (bool) preg_match( '#^(client|assets|build|vendor)/#', $relative_path );
246 }
247
248 /**
249 * Check if a script URL belongs to WordPress core.
250 *
251 * WordPress core scripts (wp-includes, wp-admin) won't use wc.* globals,
252 * so we can skip them to reduce registry size.
253 *
254 * @param string $url Script URL.
255 * @return bool
256 */
257 private function is_wordpress_core_script( string $url ): bool {
258 return (bool) preg_match( '#/(wp-includes|wp-admin)/#', $url );
259 }
260
261 /**
262 * Recursively get all dependencies including nested ones.
263 *
264 * @param array<string> $deps Direct dependencies.
265 * @return array<string> All dependencies (flattened).
266 */
267 private function get_all_dependencies( array $deps ): array {
268 $wp_scripts = wp_scripts();
269 $all_deps = array();
270 $deps_to_process = $deps;
271
272 while ( ! empty( $deps_to_process ) ) {
273 $handle = array_shift( $deps_to_process );
274
275 if ( in_array( $handle, $all_deps, true ) ) {
276 continue;
277 }
278
279 $all_deps[] = $handle;
280
281 // Add nested dependencies to process.
282 if ( isset( $wp_scripts->registered[ $handle ] ) ) {
283 foreach ( $wp_scripts->registered[ $handle ]->deps as $nested_dep ) {
284 if ( ! in_array( $nested_dep, $all_deps, true ) ) {
285 $deps_to_process[] = $nested_dep;
286 }
287 }
288 }
289 }
290
291 // Filter to only include WooCommerce handles we care about.
292 $wc_handles = array_values( self::WC_GLOBAL_EXPORTS );
293 return array_values(
294 array_filter(
295 $all_deps,
296 function ( $dep ) use ( $wc_handles ) {
297 return in_array( $dep, $wc_handles, true );
298 }
299 )
300 );
301 }
302
303 /**
304 * Check if the current page contains any of the tracked blocks.
305 * Checks post content, widget areas, and template parts (header) for blocks.
306 *
307 * @return bool True if page has tracked blocks.
308 */
309 private function page_has_tracked_blocks(): bool {
310 // Check post content for blocks.
311 foreach ( self::TRACKED_BLOCKS as $block_name ) {
312 if ( \has_block( $block_name ) ) {
313 return true;
314 }
315 }
316
317 // Check widget areas for mini-cart (classic themes).
318 $mini_cart_in_widgets = BlocksUtil::get_blocks_from_widget_area( 'woocommerce/mini-cart' );
319 if ( ! empty( $mini_cart_in_widgets ) ) {
320 return true;
321 }
322
323 // Check header template part for mini-cart (block themes).
324 try {
325 $mini_cart_in_header = BlocksUtil::get_block_from_template_part( 'woocommerce/mini-cart', 'header' );
326 if ( ! empty( $mini_cart_in_header ) ) {
327 return true;
328 }
329 } catch ( \Throwable $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
330 // Template part may not exist in all themes, silently continue.
331 }
332
333 return false;
334 }
335
336 /**
337 * Normalize a URL by removing query strings and hash fragments.
338 *
339 * This helps match URLs in stack traces which don't include query strings.
340 *
341 * @param string $url URL to normalize.
342 * @return string Normalized URL without query string or hash.
343 */
344 private function normalize_url( string $url ): string {
345 $scheme = wp_parse_url( $url, PHP_URL_SCHEME );
346 $host = wp_parse_url( $url, PHP_URL_HOST );
347 $path = wp_parse_url( $url, PHP_URL_PATH );
348
349 if ( $scheme && $host && $path ) {
350 $port = wp_parse_url( $url, PHP_URL_PORT );
351 return $scheme . '://' . $host . ( $port ? ':' . $port : '' ) . $path;
352 }
353
354 return $url;
355 }
356 }
357