From 816761c618010faa61448a8f7e149a8701bfc477 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Fri, 9 Jun 2023 14:20:16 -0400 Subject: [PATCH 1/6] allow for handling classic theme template part support Note this logic is currently not right - just a quick implementation for testing POC --- src/Utils/BlockTemplateUtils.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 0a65a3cbcc1..09c053a4bae 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -440,17 +440,21 @@ public static function theme_has_template_part( $template_name ) { /** * Checks to see if they are using a compatible version of WP, or if not they have a compatible version of the Gutenberg plugin installed. * + * @param boolean $template_part Whether we are checking for a template part or not. * @return boolean */ - public static function supports_block_templates() { - if ( - ! wc_current_theme_is_fse_theme() && - ( ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() ) - ) { - return false; + public static function supports_block_templates( $template_part = false ) { + if ( (bool) $template_part && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { + return true; + } else { + if ( + ! wc_current_theme_is_fse_theme() && + ( ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() ) + ) { + return false; + } + return true; } - - return true; } /** From 6aa13847f3abf1f73cacdc87be3e8092619fa4ed Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Fri, 9 Jun 2023 14:20:38 -0400 Subject: [PATCH 2/6] Account for classic theme support of template parts --- src/BlockTemplatesController.php | 2 +- src/BlockTypes/MiniCart.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index 6cf131b9bc7..a4b37ee6060 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -295,7 +295,7 @@ public function get_block_file_template( $template, $id, $template_type ) { * @return array */ public function add_block_templates( $query_result, $query, $template_type ) { - if ( ! BlockTemplateUtils::supports_block_templates() ) { + if ( ! BlockTemplateUtils::supports_block_templates( 'wp_template_part' === $template_type ) ) { return $query_result; } diff --git a/src/BlockTypes/MiniCart.php b/src/BlockTypes/MiniCart.php index 60b33ae98de..11bd7530df3 100644 --- a/src/BlockTypes/MiniCart.php +++ b/src/BlockTypes/MiniCart.php @@ -155,7 +155,7 @@ protected function enqueue_data( array $attributes = [] ) { if ( current_user_can( 'edit_theme_options' ) && - wc_current_theme_is_fse_theme() + ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { $theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG; From f6920405001f6d8d22abe84e00f02666dd574f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 11 Jul 2023 15:50:33 +0200 Subject: [PATCH 3/6] Update supports_block_templates signature so it accepts the template type instead of a bool --- src/BlockTemplatesController.php | 2 +- src/Utils/BlockTemplateUtils.php | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index a4b37ee6060..a3021607e79 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -295,7 +295,7 @@ public function get_block_file_template( $template, $id, $template_type ) { * @return array */ public function add_block_templates( $query_result, $query, $template_type ) { - if ( ! BlockTemplateUtils::supports_block_templates( 'wp_template_part' === $template_type ) ) { + if ( ! BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) { return $query_result; } diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 09c053a4bae..a5d9ff74f2f 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -440,11 +440,12 @@ public static function theme_has_template_part( $template_name ) { /** * Checks to see if they are using a compatible version of WP, or if not they have a compatible version of the Gutenberg plugin installed. * - * @param boolean $template_part Whether we are checking for a template part or not. + * @param string $template_type Optional. Template type: `wp_template` or `wp_template_part`. + * Default `wp_template`. * @return boolean */ - public static function supports_block_templates( $template_part = false ) { - if ( (bool) $template_part && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { + public static function supports_block_templates( $template_type = 'wp_template' ) { + if ( 'wp_template_part' === $template_type && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { return true; } else { if ( @@ -461,8 +462,8 @@ public static function supports_block_templates( $template_part = false ) { * Retrieves a single unified template object using its id. * * @param string $id Template unique identifier (example: theme_slug//template_slug). - * @param string $template_type Optional. Template type: `'wp_template'` or '`wp_template_part'`. - * Default `'wp_template'`. + * @param string $template_type Optional. Template type: `wp_template` or 'wp_template_part`. + * Default `wp_template`. * * @return WP_Block_Template|null Template. */ From 64b79d088b8faf28903c1f0e693409a30b8a6f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 11 Jul 2023 16:06:58 +0200 Subject: [PATCH 4/6] Simplify logic in supports_block_templates --- src/Utils/BlockTemplateUtils.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index a5d9ff74f2f..d6e63110c3b 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -446,16 +446,11 @@ public static function theme_has_template_part( $template_name ) { */ public static function supports_block_templates( $template_type = 'wp_template' ) { if ( 'wp_template_part' === $template_type && ( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) ) ) { - return true; - } else { - if ( - ! wc_current_theme_is_fse_theme() && - ( ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() ) - ) { - return false; - } + return true; + } elseif ( 'wp_template' === $template_type && wc_current_theme_is_fse_theme() ) { return true; } + return false; } /** From d5976f6cf787598508ef857b893f160b1d318a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 11 Jul 2023 16:21:38 +0200 Subject: [PATCH 5/6] Test --- woocommerce-gutenberg-products-block.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index cf0f68ab4ca..60f54a154c7 100644 --- a/woocommerce-gutenberg-products-block.php +++ b/woocommerce-gutenberg-products-block.php @@ -7,7 +7,7 @@ * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block - * Requires at least: 6.2 + * Requires at least: 6.1 * Requires PHP: 7.3 * WC requires at least: 7.7 * WC tested up to: 7.8 @@ -18,7 +18,7 @@ defined( 'ABSPATH' ) || exit; -$minimum_wp_version = '6.2'; +$minimum_wp_version = '6.1'; if ( ! defined( 'WC_BLOCKS_IS_FEATURE_PLUGIN' ) ) { define( 'WC_BLOCKS_IS_FEATURE_PLUGIN', true ); From 1843a9a35067ddf97b1e148af52ca411bab17420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 12 Jul 2023 14:35:33 +0200 Subject: [PATCH 6/6] Fix supports_block_templates check to test correct template type --- src/BlockTemplatesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index a3021607e79..49f6878d13f 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -295,7 +295,7 @@ public function get_block_file_template( $template, $id, $template_type ) { * @return array */ public function add_block_templates( $query_result, $query, $template_type ) { - if ( ! BlockTemplateUtils::supports_block_templates( 'wp_template_part' ) ) { + if ( ! BlockTemplateUtils::supports_block_templates( $template_type ) ) { return $query_result; }