PHP 8.2.31
Preview: ClassicTemplatesCompatibility.php Size: 2.37 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Blocks/Templates/ClassicTemplatesCompatibility.php

<?php
namespace Automattic\WooCommerce\Blocks\Templates;

use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;

/**
 * ClassicTemplatesCompatibility class.
 *
 * To bridge the gap on compatibility with widget blocks and classic PHP core templates.
 *
 * @internal
 */
class ClassicTemplatesCompatibility {

	/**
	 * Instance of the asset data registry.
	 *
	 * @var AssetDataRegistry
	 */
	protected $asset_data_registry;

	/**
	 * Constructor.
	 *
	 * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry.
	 */
	public function __construct( AssetDataRegistry $asset_data_registry ) {
		$this->asset_data_registry = $asset_data_registry;
		$this->init();
	}

	/**
	 * Initialization method.
	 */
	protected function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingPublic
		if ( ! wp_is_block_theme() ) {
			add_action( 'template_redirect', array( $this, 'set_classic_template_data' ) );
			// We need to set this data on the widgets screen so the filters render previews.
			add_action( 'load-widgets.php', array( $this, 'set_filterable_product_data' ) );
		}
	}

	/**
	 * Executes the methods which set the necessary data needed for filter blocks to work correctly as widgets in Classic templates.
	 *
	 * @return void
	 */
	public function set_classic_template_data() {
		$this->set_filterable_product_data();
		$this->set_php_template_data();
	}

	/**
	 * This method passes the value `has_filterable_products` to the front-end for product archive pages,
	 * so that widget product filter blocks are aware of the context they are in and can render accordingly.
	 *
	 * @return void
	 */
	public function set_filterable_product_data() {
		global $pagenow;

		if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) {
			$this->asset_data_registry->add( 'hasFilterableProducts', true );
		}
	}

	/**
	 * This method passes the value `is_rendering_php_template` to the front-end of Classic themes,
	 * so that widget product filter blocks are aware of how to filter the products.
	 *
	 * This data only matters on WooCommerce product archive pages.
	 * On non-archive pages the merchant could be using the All Products block which is not a PHP template.
	 *
	 * @return void
	 */
	public function set_php_template_data() {
		if ( is_shop() || is_product_taxonomy() ) {
			$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
		}
	}
}

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
1.81 KB lrw-r--r-- 2024-08-27 23:04:44
Edit Download
737 B lrw-r--r-- 2025-09-01 23:44:48
Edit Download
5.76 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
332 B lrw-r--r-- 2024-03-26 16:56:02
Edit Download
1.80 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
12.43 KB lrw-r--r-- 2024-09-23 20:44:04
Edit Download
1.96 KB lrw-r--r-- 2025-09-01 23:44:48
Edit Download
863 B lrw-r--r-- 2024-03-26 16:56:02
Edit Download
2.00 KB lrw-r--r-- 2025-09-01 23:44:48
Edit Download
2.37 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
1.11 KB lrw-r--r-- 2024-12-18 22:19:16
Edit Download
2.58 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
1021 B lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1016 B lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1.67 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
1.58 KB lrw-r--r-- 2024-08-27 23:04:44
Edit Download
2.69 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
1.74 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
2.26 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
1.74 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
2.02 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
1.72 KB lrw-r--r-- 2025-11-24 23:10:10
Edit Download
1011 B lrw-r--r-- 2025-06-23 19:46:28
Edit Download
9.58 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
14.43 KB lrw-r--r-- 2025-09-01 23:44:48
Edit Download
1021 B lrw-r--r-- 2025-06-23 19:46:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).