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.2.0 10.0.1 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3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.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 / Domain / Bootstrap.php
woocommerce / src / Blocks / Domain Last commit date
Services 2 weeks ago BlockRegistrationContext.php 2 weeks ago Bootstrap.php 2 weeks ago Package.php 1 year ago
Bootstrap.php
549 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\Domain;
3
4 use Automattic\Jetpack\Constants;
5 use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi;
6 use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
7 use Automattic\WooCommerce\Blocks\AssetsController;
8 use Automattic\WooCommerce\Blocks\BlockPatterns;
9 use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
10 use Automattic\WooCommerce\Blocks\BlockTemplatesController;
11 use Automattic\WooCommerce\Blocks\BlockTypesController;
12 use Automattic\WooCommerce\Blocks\CoreBreadcrumbsCompatibility;
13 use Automattic\WooCommerce\Blocks\DependencyDetection;
14 use Automattic\WooCommerce\Blocks\Patterns\PatternRegistry;
15 use Automattic\WooCommerce\Blocks\Patterns\PTKClient;
16 use Automattic\WooCommerce\Blocks\Patterns\PTKPatternsStore;
17 use Automattic\WooCommerce\Blocks\Domain\Services\Notices;
18 use Automattic\WooCommerce\Blocks\Domain\Services\DraftOrders;
19 use Automattic\WooCommerce\Blocks\Domain\Services\GoogleAnalytics;
20 use Automattic\WooCommerce\Blocks\Domain\Services\Hydration;
21 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
22 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldsAdmin;
23 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFieldsFrontend;
24 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutLink;
25 use Automattic\WooCommerce\Blocks\InboxNotifications;
26 use Automattic\WooCommerce\Blocks\Installer;
27 use Automattic\WooCommerce\Blocks\Payments\Api as PaymentsApi;
28 use Automattic\WooCommerce\Blocks\Payments\Integrations\BankTransfer;
29 use Automattic\WooCommerce\Blocks\Payments\Integrations\CashOnDelivery;
30 use Automattic\WooCommerce\Blocks\Payments\Integrations\Cheque;
31 use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal;
32 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
33 use Automattic\WooCommerce\Blocks\Registry\Container;
34 use Automattic\WooCommerce\Blocks\Templates\ClassicTemplatesCompatibility;
35 use Automattic\WooCommerce\StoreApi\RoutesController;
36 use Automattic\WooCommerce\StoreApi\SchemaController;
37 use Automattic\WooCommerce\StoreApi\StoreApi;
38 use Automattic\WooCommerce\Blocks\Shipping\ShippingController;
39 use Automattic\WooCommerce\Blocks\TemplateOptions;
40 use Automattic\WooCommerce\Internal\Features\BlockEditorUnifiedAssets;
41
42
43 /**
44 * Takes care of bootstrapping the plugin.
45 *
46 * @since 2.5.0
47 */
48 class Bootstrap {
49
50 /**
51 * Holds the Dependency Injection Container
52 *
53 * @var Container
54 */
55 private $container;
56
57 /**
58 * Holds the Package instance
59 *
60 * @var Package
61 */
62 private $package;
63
64 /**
65 * Constructor
66 *
67 * @param Container $container The Dependency Injection Container.
68 */
69 public function __construct( Container $container ) {
70 $this->container = $container;
71 $this->package = $container->get( Package::class );
72
73 $this->init();
74 /**
75 * Fires when the woocommerce blocks are loaded and ready to use.
76 *
77 * This hook is intended to be used as a safe event hook for when the plugin
78 * has been loaded, and all dependency requirements have been met.
79 *
80 * To ensure blocks are initialized, you must use the `woocommerce_blocks_loaded`
81 * hook instead of the `plugins_loaded` hook. This is because the functions
82 * hooked into plugins_loaded on the same priority load in an inconsistent and unpredictable manner.
83 *
84 * @since 2.5.0
85 */
86 do_action( 'woocommerce_blocks_loaded' );
87 }
88
89 /**
90 * Init the package - load the blocks library and define constants.
91 */
92 protected function init() {
93 $this->register_dependencies();
94 $this->register_payment_methods();
95
96 add_action(
97 'admin_init',
98 function () {
99 // Delete this notification because the blocks are included in WC Core now. This will handle any sites
100 // with lingering notices.
101 InboxNotifications::delete_surface_cart_checkout_blocks_notification();
102 },
103 10,
104 0
105 );
106
107 // We need to initialize BlockTemplatesController and BlockTemplatesRegistry at the end of `after_setup_theme`
108 // so themes had the opportunity to declare support for template parts.
109 add_action(
110 'after_setup_theme',
111 function () {
112 $is_store_api_request = wc()->is_store_api_request();
113
114 if ( ! $is_store_api_request && ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) ) {
115 $this->container->get( BlockTemplatesRegistry::class )->init();
116 $this->container->get( BlockTemplatesController::class )->init();
117 }
118 },
119 999
120 );
121
122 $is_rest = wc()->is_rest_api_request();
123 $is_store_api_request = wc()->is_store_api_request();
124
125 // Initialize Store API in non-admin context.
126 if ( ! is_admin() ) {
127 $this->container->get( StoreApi::class )->init();
128 }
129
130 // Load and init assets.
131 $this->container->get( PaymentsApi::class )->init();
132 $this->container->get( DraftOrders::class )->init();
133 $this->container->get( ShippingController::class )->init();
134 $this->container->get( CheckoutFields::class )->init();
135 $this->container->get( CheckoutLink::class )->init();
136 $this->container->get( AssetDataRegistry::class );
137 $this->container->get( AssetsController::class );
138 $this->container->get( DependencyDetection::class );
139
140 // Load assets in admin and on the frontend.
141 if ( ! $is_rest ) {
142 $this->add_build_notice();
143 $this->container->get( Installer::class )->init();
144 $this->container->get( GoogleAnalytics::class )->init();
145 $this->container->get( is_admin() ? CheckoutFieldsAdmin::class : CheckoutFieldsFrontend::class )->init();
146 }
147
148 // Register block types on demand (priority 8, before do_blocks at 9) so blocks in a description are not empty.
149 add_filter( 'woocommerce_short_description', array( $this, 'maybe_register_blocks_from_content' ), 8 );
150
151 // Load assets unless this is a request specifically for the store API.
152 if ( ! $is_store_api_request ) {
153 // Skip eager block/pattern/asset registration on non-rendering requests; the block types needed for
154 // a description block are still registered on demand (see the hook above). See BlockRegistrationContext.
155 if ( ( new BlockRegistrationContext() )->should_register() ) {
156 $this->container->get( BlockPatterns::class );
157 $this->container->get( BlockTypesController::class );
158 }
159 $this->container->get( ClassicTemplatesCompatibility::class );
160 $this->container->get( Notices::class )->init();
161
162 if ( is_admin() || $is_rest ) {
163 $this->container->get( PTKPatternsStore::class );
164 }
165
166 if ( is_admin() ) {
167 $this->container->get( TemplateOptions::class )->init();
168 }
169 }
170 }
171
172 /**
173 * Register WooCommerce block types on demand when a description containing one is rendered.
174 *
175 * Eager block registration is skipped on non-rendering requests (Store API, REST, AJAX, webhooks), but
176 * product and variation descriptions still run through do_blocks there, so a WooCommerce block in a
177 * description would render empty. Hooked to woocommerce_short_description just before do_blocks.
178 *
179 * The detection also fires on a synced pattern reference (core/block, `wp:block`): the referenced pattern's
180 * content is not available here without fetching it, so registration happens defensively in case it
181 * contains a WooCommerce block; registering covers nested blocks at any depth.
182 *
183 * @since 11.1.0
184 *
185 * @param string $content The description content passed through the filter.
186 * @return string The unchanged content.
187 */
188 public function maybe_register_blocks_from_content( $content ) {
189 if ( is_string( $content ) && preg_match( '/<!--\s+wp:(woocommerce\/|block\s)/', $content ) ) {
190 $block_types_controller = $this->container->get( BlockTypesController::class );
191 if ( ! $block_types_controller->register_blocks_has_run() ) {
192 $block_types_controller->register_blocks();
193 }
194 }
195
196 return $content;
197 }
198
199 /**
200 * See if files have been built or not.
201 *
202 * @return bool
203 */
204 protected function is_built() {
205 $editor_asset = $this->is_block_editor_unified_assets_enabled_during_bootstrap() ? 'wc-block-library.js' : 'featured-product.js';
206
207 return file_exists(
208 $this->package->get_path( 'assets/client/blocks/' . $editor_asset )
209 );
210 }
211
212 /**
213 * Check whether unified block editor assets are enabled during plugin bootstrap.
214 *
215 * Feature definitions contain translated presentation strings and are not safe to use before init.
216 *
217 * @return bool
218 */
219 private function is_block_editor_unified_assets_enabled_during_bootstrap(): bool {
220 // Keep this fallback aligned with `enabled_by_default` for unified block editor assets in FeaturesController.
221 return 'yes' === get_option( BlockEditorUnifiedAssets::OPTION_NAME, 'no' );
222 }
223
224 /**
225 * Add a notice stating that the build has not been done yet.
226 */
227 protected function add_build_notice() {
228 if ( $this->is_built() ) {
229 return;
230 }
231 add_action(
232 'admin_notices',
233 function () {
234 echo '<div class="error"><p>';
235 printf(
236 /* translators: %1$s is the install command, %2$s is the build command, %3$s is the watch command. */
237 esc_html__( 'WooCommerce Blocks development mode requires files to be built. From the root directory, run %1$s to install dependencies, %2$s to build the files or %3$s to build the files and watch for changes.', 'woocommerce' ),
238 '<code>pnpm install</code>',
239 '<code>pnpm --filter="@woocommerce/plugin-woocommerce" build</code>',
240 '<code>pnpm --filter="@woocommerce/plugin-woocommerce" watch:build</code>'
241 );
242 echo '</p></div>';
243 }
244 );
245 }
246
247 /**
248 * Register core dependencies with the container.
249 */
250 protected function register_dependencies() {
251 $this->container->register(
252 AssetApi::class,
253 function ( Container $container ) {
254 return new AssetApi( $container->get( Package::class ) );
255 }
256 );
257 $this->container->register(
258 AssetDataRegistry::class,
259 function ( Container $container ) {
260 return new AssetDataRegistry( $container->get( AssetApi::class ) );
261 }
262 );
263 $this->container->register(
264 AssetsController::class,
265 function ( Container $container ) {
266 return new AssetsController( $container->get( AssetApi::class ) );
267 }
268 );
269 $this->container->register(
270 DependencyDetection::class,
271 function () {
272 return new DependencyDetection();
273 }
274 );
275 $this->container->register(
276 PaymentMethodRegistry::class,
277 function () {
278 return new PaymentMethodRegistry();
279 }
280 );
281 $this->container->register(
282 Installer::class,
283 function () {
284 return new Installer();
285 }
286 );
287 $this->container->register(
288 BlockTypesController::class,
289 function ( Container $container ) {
290 $asset_api = $container->get( AssetApi::class );
291 $asset_data_registry = $container->get( AssetDataRegistry::class );
292 return new BlockTypesController( $asset_api, $asset_data_registry );
293 }
294 );
295 $this->container->register(
296 CoreBreadcrumbsCompatibility::class,
297 function () {
298 return new CoreBreadcrumbsCompatibility();
299 }
300 );
301 $this->container->register(
302 ClassicTemplatesCompatibility::class,
303 function ( Container $container ) {
304 $asset_data_registry = $container->get( AssetDataRegistry::class );
305 return new ClassicTemplatesCompatibility( $asset_data_registry );
306 }
307 );
308 $this->container->register(
309 DraftOrders::class,
310 function ( Container $container ) {
311 return new DraftOrders( $container->get( Package::class ) );
312 }
313 );
314 $this->container->register(
315 GoogleAnalytics::class,
316 function ( Container $container ) {
317 $asset_api = $container->get( AssetApi::class );
318 return new GoogleAnalytics( $asset_api );
319 }
320 );
321 $this->container->register(
322 Notices::class,
323 function ( Container $container ) {
324 return new Notices( $container->get( Package::class ) );
325 }
326 );
327 $this->container->register(
328 Hydration::class,
329 function ( Container $container ) {
330 return new Hydration( $container->get( AssetDataRegistry::class ) );
331 }
332 );
333 $this->container->register(
334 CheckoutFields::class,
335 function ( Container $container ) {
336 return new CheckoutFields( $container->get( AssetDataRegistry::class ) );
337 }
338 );
339 $this->container->register(
340 CheckoutFieldsAdmin::class,
341 function ( Container $container ) {
342 $checkout_fields_controller = $container->get( CheckoutFields::class );
343 return new CheckoutFieldsAdmin( $checkout_fields_controller );
344 }
345 );
346 $this->container->register(
347 CheckoutFieldsFrontend::class,
348 function ( Container $container ) {
349 $checkout_fields_controller = $container->get( CheckoutFields::class );
350 return new CheckoutFieldsFrontend( $checkout_fields_controller );
351 }
352 );
353 $this->container->register(
354 PaymentsApi::class,
355 function ( Container $container ) {
356 $payment_method_registry = $container->get( PaymentMethodRegistry::class );
357 $asset_data_registry = $container->get( AssetDataRegistry::class );
358 return new PaymentsApi( $payment_method_registry, $asset_data_registry );
359 }
360 );
361 $this->container->register(
362 CheckoutLink::class,
363 function () {
364 return new CheckoutLink();
365 }
366 );
367 $this->container->register(
368 StoreApi::class,
369 function () {
370 return new StoreApi();
371 }
372 );
373 $this->container->register(
374 TemplateOptions::class,
375 function () {
376 return new TemplateOptions();
377 }
378 );
379 // Maintains backwards compatibility with previous Store API namespace.
380 $this->container->register(
381 'Automattic\WooCommerce\Blocks\StoreApi\Formatters',
382 function ( Container $container ) {
383 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '6.4.0', 'Automattic\WooCommerce\StoreApi\Formatters', '6.5.0' );
384 return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Formatters::class );
385 }
386 );
387 $this->container->register(
388 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi',
389 function ( Container $container ) {
390 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '6.4.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '6.5.0' );
391 return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class );
392 }
393 );
394 $this->container->register(
395 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController',
396 function ( Container $container ) {
397 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '6.4.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '6.5.0' );
398 return $container->get( StoreApi::class )->container()->get( SchemaController::class );
399 }
400 );
401 $this->container->register(
402 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController',
403 function ( Container $container ) {
404 $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '6.4.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '6.5.0' );
405 return $container->get( StoreApi::class )->container()->get( RoutesController::class );
406 }
407 );
408 $this->container->register(
409 PTKClient::class,
410 function () {
411 return new PTKClient();
412 }
413 );
414 $this->container->register(
415 PTKPatternsStore::class,
416 function () {
417 return new PTKPatternsStore( $this->container->get( PTKClient::class ) );
418 }
419 );
420 $this->container->register(
421 BlockPatterns::class,
422 function () {
423 return new BlockPatterns(
424 $this->package,
425 new PatternRegistry(),
426 $this->container->get( PTKPatternsStore::class )
427 );
428 }
429 );
430 $this->container->register(
431 ShippingController::class,
432 function ( $container ) {
433 $asset_api = $container->get( AssetApi::class );
434 $asset_data_registry = $container->get( AssetDataRegistry::class );
435 return new ShippingController( $asset_api, $asset_data_registry );
436 }
437 );
438 $this->container->register(
439 BlockTemplatesRegistry::class,
440 function () {
441 return new BlockTemplatesRegistry();
442 }
443 );
444 $this->container->register(
445 BlockTemplatesController::class,
446 function () {
447 return new BlockTemplatesController();
448 }
449 );
450 }
451
452 /**
453 * Throws a deprecation notice for a dependency without breaking requests.
454 *
455 * @param string $function Class or function being deprecated.
456 * @param string $version Version in which it was deprecated.
457 * @param string $replacement Replacement class or function, if applicable.
458 * @param string $trigger_error_version Optional version to start surfacing this as a PHP error rather than a log. Defaults to $version.
459 */
460 protected function deprecated_dependency( $function, $version, $replacement = '', $trigger_error_version = '' ) {
461 if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
462 return;
463 }
464
465 $trigger_error_version = $trigger_error_version ? $trigger_error_version : $version;
466 $error_message = $replacement ? sprintf(
467 '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
468 $function,
469 $version,
470 $replacement
471 ) : sprintf(
472 '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
473 $function,
474 $version
475 );
476 /**
477 * Fires when a deprecated function is called.
478 *
479 * @since 7.3.0
480 */
481 do_action( 'deprecated_function_run', $function, $replacement, $version );
482
483 $log_error = false;
484
485 // If headers have not been sent yet, log to avoid breaking the request.
486 if ( ! headers_sent() ) {
487 $log_error = true;
488 }
489
490 // If the $trigger_error_version was not yet reached, only log the error.
491 if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $trigger_error_version, '<' ) ) {
492 $log_error = true;
493 }
494
495 /**
496 * Filters whether to trigger an error for deprecated functions. (Same as WP core)
497 *
498 * @since 7.3.0
499 *
500 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
501 */
502 if ( ! apply_filters( 'deprecated_function_trigger_error', true ) ) {
503 $log_error = true;
504 }
505
506 if ( $log_error ) {
507 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
508 error_log( $error_message );
509 } else {
510 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
511 trigger_error( $error_message, E_USER_DEPRECATED );
512 }
513 }
514
515 /**
516 * Register payment method integrations with the container.
517 */
518 protected function register_payment_methods() {
519 $this->container->register(
520 Cheque::class,
521 function ( Container $container ) {
522 $asset_api = $container->get( AssetApi::class );
523 return new Cheque( $asset_api );
524 }
525 );
526 $this->container->register(
527 PayPal::class,
528 function ( Container $container ) {
529 $asset_api = $container->get( AssetApi::class );
530 return new PayPal( $asset_api );
531 }
532 );
533 $this->container->register(
534 BankTransfer::class,
535 function ( Container $container ) {
536 $asset_api = $container->get( AssetApi::class );
537 return new BankTransfer( $asset_api );
538 }
539 );
540 $this->container->register(
541 CashOnDelivery::class,
542 function ( Container $container ) {
543 $asset_api = $container->get( AssetApi::class );
544 return new CashOnDelivery( $asset_api );
545 }
546 );
547 }
548 }
549