From 645bd8d339d2be577edbeb9bbc8c4fd5fc07fcc2 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 10 Oct 2023 16:50:18 +0200 Subject: [PATCH] Add feature gate for the block templates controller refactor (https://github.com/woocommerce/woocommerce-blocks/pull/11178) * add feature gating for the block templates controller refactor * improve check --- .../src/BlockTemplatesController.php | 5 ++++- .../src/Domain/Services/FeatureGating.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index f0559ec586b..7538cea4e1f 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -42,8 +42,11 @@ class BlockTemplatesController { public function __construct( Package $package ) { $this->package = $package; + $feature_gating = $package->feature(); + $is_block_templates_controller_refactor_enabled = $feature_gating->is_block_templates_controller_refactor_enabled(); + // This feature is gated for WooCommerce versions 6.0.0 and above. - if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) { + if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) && ! $is_block_templates_controller_refactor_enabled ) { $this->init(); } } diff --git a/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php b/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php index 250187dc7e0..bfa5349d2cb 100644 --- a/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php +++ b/plugins/woocommerce-blocks/src/Domain/Services/FeatureGating.php @@ -164,4 +164,15 @@ class FeatureGating { return self::EXPERIMENTAL_FLAG; } + + /** + * Check if the block templates controller refactor should be used to display blocks. + * + * @return boolean + */ + public function is_block_templates_controller_refactor_enabled() { + $conf = parse_ini_file( __DIR__ . '/../../../blocks.ini' ); + return $this->is_development_environment() && isset( $conf['use_block_templates_controller_refactor'] ) && true === (bool) $conf['use_block_templates_controller_refactor']; + } + }