From 79671e6defc1ca3a123ebc1e25b297a20493d6e8 Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Fri, 24 Dec 2021 19:27:56 +0100 Subject: [PATCH 01/10] Move block templates and parts directories to the Gutenberg 12.1.0 convention Gutenberg 12.1.0 has changed the convention for the directory paths from `block-templates` and `block-template-parts` to `templates` and `parts` respectively. We are also moving to that convention but making sure that we remain backwards-compatible. Fixes #5450, #5343 --- src/BlockTemplatesController.php | 52 ++++++++++---- src/Utils/BlockTemplateUtils.php | 72 +++++++++++++++---- .../mini-cart.html | 0 .../archive-product.html | 0 .../my-test-template.html} | 0 templates/templates/single-product.html | 5 ++ .../taxonomy-product_cat.html | 0 .../taxonomy-product_tag.html | 0 8 files changed, 103 insertions(+), 26 deletions(-) rename templates/{block-template-parts => parts}/mini-cart.html (100%) rename templates/{block-templates => templates}/archive-product.html (100%) rename templates/{block-templates/single-product.html => templates/my-test-template.html} (100%) create mode 100644 templates/templates/single-product.html rename templates/{block-templates => templates}/taxonomy-product_cat.html (100%) rename templates/{block-templates => templates}/taxonomy-product_tag.html (100%) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index c8abf43ce5c..aaa57d01d3a 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -25,18 +25,47 @@ class BlockTemplatesController { private $template_parts_directory; /** - * Directory name of the block template directory. + * Directory name of all the templates. * * @var string */ - const TEMPLATES_DIR_NAME = 'block-templates'; + const TEMPLATES_ROOT_DIR = 'templates'; + + /** + * Old directory name of the block templates directory. + * + * The convention has changed with Gutenberg 12.1.0, but we need to keep this + * for backwards compatibility. + * + * @deprecated + * @var string + */ + const DEPRECATED_TEMPLATES_DIR_NAME = 'block-templates'; + + /** + * Old directory name of the block template parts directory. + * + * The convention has changed with Gutenberg 12.1.0, but we need to keep this + * for backwards compatibility. + * + * @deprecated + * @var string + */ + const DEPRECATED_TEMPLATE_PARTS_DIR_NAME = 'block-templates-parts'; + + /** + * Directory name of the block templates directory. + * + * @var string + */ + const TEMPLATES_DIR_NAME = 'templates'; /** * Directory name of the block template parts directory. * * @var string */ - const TEMPLATE_PARTS_DIR_NAME = 'block-template-parts'; + const TEMPLATE_PARTS_DIR_NAME = 'parts'; /** * Constructor. @@ -44,8 +73,10 @@ class BlockTemplatesController { public function __construct() { // This feature is gated for WooCommerce versions 6.0.0 and above. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) { - $this->templates_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATES_DIR_NAME; - $this->template_parts_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATE_PARTS_DIR_NAME; + $root_path = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR; + + $this->templates_directory = $root_path . self::TEMPLATES_DIR_NAME; + $this->template_parts_directory = $root_path . self::TEMPLATE_PARTS_DIR_NAME; $this->init(); } } @@ -311,15 +342,8 @@ public function get_block_templates_from_woocommerce( $slugs, $already_found_tem $template_files = BlockTemplateUtils::gutenberg_get_template_paths( $directory ); $templates = array(); - if ( 'wp_template_part' === $template_type ) { - $dir_name = self::TEMPLATE_PARTS_DIR_NAME; - } else { - $dir_name = self::TEMPLATES_DIR_NAME; - } - foreach ( $template_files as $template_file ) { - $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file, $dir_name ); - + $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file ); // This template does not have a slug we're looking for. Skip it. if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) { continue; @@ -343,7 +367,7 @@ function ( $template ) use ( $template_slug ) { // If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) { - $template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html'; + $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' ); $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true ); continue; } diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index cbc61f39e77..bf295ac4d2f 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -1,6 +1,8 @@ + +
+ + diff --git a/templates/block-templates/taxonomy-product_cat.html b/templates/templates/taxonomy-product_cat.html similarity index 100% rename from templates/block-templates/taxonomy-product_cat.html rename to templates/templates/taxonomy-product_cat.html diff --git a/templates/block-templates/taxonomy-product_tag.html b/templates/templates/taxonomy-product_tag.html similarity index 100% rename from templates/block-templates/taxonomy-product_tag.html rename to templates/templates/taxonomy-product_tag.html From dfbdfb517f252fc6c648ae793a0bc13e271b6a97 Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 17:57:03 +0100 Subject: [PATCH 02/10] Revert changes on our own block templates Will open a different PR to address #5343 --- src/BlockTemplatesController.php | 52 +++++-------------- .../archive-product.html | 0 .../single-product.html | 0 .../taxonomy-product_cat.html | 0 .../taxonomy-product_tag.html | 0 .../mini-cart.html | 0 templates/templates/my-test-template.html | 5 -- 7 files changed, 14 insertions(+), 43 deletions(-) rename templates/{templates => block-template}/archive-product.html (100%) rename templates/{templates => block-template}/single-product.html (100%) rename templates/{templates => block-template}/taxonomy-product_cat.html (100%) rename templates/{templates => block-template}/taxonomy-product_tag.html (100%) rename templates/{parts => block-templates-parts}/mini-cart.html (100%) delete mode 100644 templates/templates/my-test-template.html diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index aaa57d01d3a..c8abf43ce5c 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -25,47 +25,18 @@ class BlockTemplatesController { private $template_parts_directory; /** - * Directory name of all the templates. + * Directory name of the block template directory. * * @var string */ - const TEMPLATES_ROOT_DIR = 'templates'; - - /** - * Old directory name of the block templates directory. - * - * The convention has changed with Gutenberg 12.1.0, but we need to keep this - * for backwards compatibility. - * - * @deprecated - * @var string - */ - const DEPRECATED_TEMPLATES_DIR_NAME = 'block-templates'; - - /** - * Old directory name of the block template parts directory. - * - * The convention has changed with Gutenberg 12.1.0, but we need to keep this - * for backwards compatibility. - * - * @deprecated - * @var string - */ - const DEPRECATED_TEMPLATE_PARTS_DIR_NAME = 'block-templates-parts'; - - /** - * Directory name of the block templates directory. - * - * @var string - */ - const TEMPLATES_DIR_NAME = 'templates'; + const TEMPLATES_DIR_NAME = 'block-templates'; /** * Directory name of the block template parts directory. * * @var string */ - const TEMPLATE_PARTS_DIR_NAME = 'parts'; + const TEMPLATE_PARTS_DIR_NAME = 'block-template-parts'; /** * Constructor. @@ -73,10 +44,8 @@ class BlockTemplatesController { public function __construct() { // This feature is gated for WooCommerce versions 6.0.0 and above. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '6.0.0', '>=' ) ) { - $root_path = plugin_dir_path( __DIR__ ) . self::TEMPLATES_ROOT_DIR . DIRECTORY_SEPARATOR; - - $this->templates_directory = $root_path . self::TEMPLATES_DIR_NAME; - $this->template_parts_directory = $root_path . self::TEMPLATE_PARTS_DIR_NAME; + $this->templates_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATES_DIR_NAME; + $this->template_parts_directory = plugin_dir_path( __DIR__ ) . 'templates/' . self::TEMPLATE_PARTS_DIR_NAME; $this->init(); } } @@ -342,8 +311,15 @@ public function get_block_templates_from_woocommerce( $slugs, $already_found_tem $template_files = BlockTemplateUtils::gutenberg_get_template_paths( $directory ); $templates = array(); + if ( 'wp_template_part' === $template_type ) { + $dir_name = self::TEMPLATE_PARTS_DIR_NAME; + } else { + $dir_name = self::TEMPLATES_DIR_NAME; + } + foreach ( $template_files as $template_file ) { - $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file ); + $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file, $dir_name ); + // This template does not have a slug we're looking for. Skip it. if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) { continue; @@ -367,7 +343,7 @@ function ( $template ) use ( $template_slug ) { // If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) { - $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' ); + $template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html'; $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true ); continue; } diff --git a/templates/templates/archive-product.html b/templates/block-template/archive-product.html similarity index 100% rename from templates/templates/archive-product.html rename to templates/block-template/archive-product.html diff --git a/templates/templates/single-product.html b/templates/block-template/single-product.html similarity index 100% rename from templates/templates/single-product.html rename to templates/block-template/single-product.html diff --git a/templates/templates/taxonomy-product_cat.html b/templates/block-template/taxonomy-product_cat.html similarity index 100% rename from templates/templates/taxonomy-product_cat.html rename to templates/block-template/taxonomy-product_cat.html diff --git a/templates/templates/taxonomy-product_tag.html b/templates/block-template/taxonomy-product_tag.html similarity index 100% rename from templates/templates/taxonomy-product_tag.html rename to templates/block-template/taxonomy-product_tag.html diff --git a/templates/parts/mini-cart.html b/templates/block-templates-parts/mini-cart.html similarity index 100% rename from templates/parts/mini-cart.html rename to templates/block-templates-parts/mini-cart.html diff --git a/templates/templates/my-test-template.html b/templates/templates/my-test-template.html deleted file mode 100644 index 1e4177d96e3..00000000000 --- a/templates/templates/my-test-template.html +++ /dev/null @@ -1,5 +0,0 @@ - - -
- - From bb52a532b27b3e3c0f6ca7acc9fe28b71f0c2774 Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 18:07:46 +0100 Subject: [PATCH 03/10] Check possible theme template parts combinations --- src/Utils/BlockTemplateUtils.php | 64 +++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index bf295ac4d2f..3ad4de3af45 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -1,13 +1,54 @@ Date: Mon, 27 Dec 2021 18:23:04 +0100 Subject: [PATCH 04/10] Remove `TEMPLATES_ROOT_DIR` const Removing as it's part of the Woo Blocks-specific migration --- src/Utils/BlockTemplateUtils.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 3ad4de3af45..786227f1402 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -6,13 +6,6 @@ * IMPORTANT: These methods have been duplicated from Gutenberg/lib/full-site-editing/block-templates.php as those functions are not for public usage. */ class BlockTemplateUtils { - /** - * Directory name of all the templates. - * - * @var string - */ - const TEMPLATES_ROOT_DIR = 'templates'; - /** * Old directory name of the block templates directory. * From 6924beec2d619d91b674914e8a6f850bd142f85f Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 18:34:20 +0100 Subject: [PATCH 05/10] Correct directory names --- .../mini-cart.html | 0 .../{block-template => block-templates}/archive-product.html | 0 templates/{block-template => block-templates}/single-product.html | 0 .../{block-template => block-templates}/taxonomy-product_cat.html | 0 .../{block-template => block-templates}/taxonomy-product_tag.html | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename templates/{block-templates-parts => block-template-parts}/mini-cart.html (100%) rename templates/{block-template => block-templates}/archive-product.html (100%) rename templates/{block-template => block-templates}/single-product.html (100%) rename templates/{block-template => block-templates}/taxonomy-product_cat.html (100%) rename templates/{block-template => block-templates}/taxonomy-product_tag.html (100%) diff --git a/templates/block-templates-parts/mini-cart.html b/templates/block-template-parts/mini-cart.html similarity index 100% rename from templates/block-templates-parts/mini-cart.html rename to templates/block-template-parts/mini-cart.html diff --git a/templates/block-template/archive-product.html b/templates/block-templates/archive-product.html similarity index 100% rename from templates/block-template/archive-product.html rename to templates/block-templates/archive-product.html diff --git a/templates/block-template/single-product.html b/templates/block-templates/single-product.html similarity index 100% rename from templates/block-template/single-product.html rename to templates/block-templates/single-product.html diff --git a/templates/block-template/taxonomy-product_cat.html b/templates/block-templates/taxonomy-product_cat.html similarity index 100% rename from templates/block-template/taxonomy-product_cat.html rename to templates/block-templates/taxonomy-product_cat.html diff --git a/templates/block-template/taxonomy-product_tag.html b/templates/block-templates/taxonomy-product_tag.html similarity index 100% rename from templates/block-template/taxonomy-product_tag.html rename to templates/block-templates/taxonomy-product_tag.html From edc44336ad0508f95b91f3929d85865b177284ba Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 19:31:37 +0100 Subject: [PATCH 06/10] Change directory names to associative array --- src/Utils/BlockTemplateUtils.php | 59 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 786227f1402..42b02728a34 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -7,40 +7,25 @@ */ class BlockTemplateUtils { /** - * Old directory name of the block templates directory. - * - * The convention has changed with Gutenberg 12.1.0, but we need to keep this - * for backwards compatibility. - * - * @deprecated - * @var string - */ - const DEPRECATED_TEMPLATES_DIR_NAME = 'block-templates'; - - /** - * Old directory name of the block template parts directory. - * - * The convention has changed with Gutenberg 12.1.0, but we need to keep this - * for backwards compatibility. - * - * @deprecated - * @var string - */ - const DEPRECATED_TEMPLATE_PARTS_DIR_NAME = 'block-templates-parts'; - - /** - * Directory name of the block templates directory. - * - * @var string - */ - const TEMPLATES_DIR_NAME = 'templates'; - - /** - * Directory name of the block template parts directory. - * - * @var string + * Directory names for block templates + * + * Directory names conventions for block templates have changed with Gutenberg 12.1.0, + * however, for backwards-compatibility, we also keep the older conventions, prefixed + * with `DEPRECATED_`. + * + * @var array { + * @var string DEPRECATED_TEMPLATES Old directory name of the block templates directory. + * @var string DEPRECATED_TEMPLATE_PARTS Old directory name of the block template parts directory. + * @var string TEMPLATES_DIR_NAME Directory name of the block templates directory. + * @var string TEMPLATE_PARTS_DIR_NAME Directory name of the block template parts directory. + * } */ - const TEMPLATE_PARTS_DIR_NAME = 'parts'; + const DIRECTORY_NAMES = array( + 'DEPRECATED_TEMPLATES' => 'block-templates', + 'DEPRECATED_TEMPLATE_PARTS' => 'parts', + 'TEMPLATES' => 'templates', + 'TEMPLATE_PARTS' => 'parts', + ); /** * Returns an array containing the references of @@ -299,11 +284,11 @@ public static function generate_template_slug_from_path( $path, $directory_name public static function get_theme_template_path( $template_slug, $template_type = 'wp_template' ) { $template_filename = $template_slug . '.html'; $possible_templates_dir = 'wp_template' === $template_type ? array( - self::TEMPLATES_DIR_NAME, - self::DEPRECATED_TEMPLATES_DIR_NAME, + self::DIRECTORY_NAMES['TEMPLATES'], + self::DIRECTORY_NAMES['DEPRECATED_TEMPLATES'], ) : array( - self::TEMPLATE_PARTS_DIR_NAME, - self::DEPRECATED_TEMPLATE_PARTS_DIR_NAME, + self::DIRECTORY_NAMES['TEMPLATE_PARTS'], + self::DIRECTORY_NAMES['DEPRECATED_TEMPLATE_PARTS'], ); // Combine the possible root directory names with either the template directory From 60c091aaa4bba9f4a82ecfa377046218544472bc Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 19:36:14 +0100 Subject: [PATCH 07/10] Get the correct theme template path for the fallback archive --- src/BlockTemplatesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index c8abf43ce5c..be1fa2ea7da 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -343,7 +343,7 @@ function ( $template ) use ( $template_slug ) { // If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) { - $template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html'; + $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' ); $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true ); continue; } From 2d375e182a982fa770a8742c618e3b908a2cf030 Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Mon, 27 Dec 2021 23:16:03 +0100 Subject: [PATCH 08/10] Fix deprecated template parts dir name --- src/Utils/BlockTemplateUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index 42b02728a34..8b6d793a63b 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -22,7 +22,7 @@ class BlockTemplateUtils { */ const DIRECTORY_NAMES = array( 'DEPRECATED_TEMPLATES' => 'block-templates', - 'DEPRECATED_TEMPLATE_PARTS' => 'parts', + 'DEPRECATED_TEMPLATE_PARTS' => 'block-template-parts', 'TEMPLATES' => 'templates', 'TEMPLATE_PARTS' => 'parts', ); From 855ae2e4523e09d09766c7845d46f0cd2547f3dc Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Tue, 28 Dec 2021 00:06:37 +0100 Subject: [PATCH 09/10] Add template check logic to `woocommerce_has_block_template` filter --- src/BlockTemplatesController.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index be1fa2ea7da..e283547cd68 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -57,6 +57,7 @@ protected function init() { add_action( 'template_redirect', array( $this, 'render_block_template' ) ); add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 ); + add_filter( 'woocommerce_has_block_template', array( $this, 'maybe_has_template' ), 10, 2 ); } /** @@ -438,4 +439,27 @@ public function render_block_template() { } } + /** + * Checks alternative paths for block templates + * + * This function is supposed to be hooked to the `woocommerce_has_block_template` filter. + * Since Gutenberg 12.1.0, directory names conventions for block templates have changed, + * however, WooCommerce still doesn't support that. Because of that, we patch the support + * by using our own checking functionality here. + * + * @see woocommerce/includes/class-wc-template-loader.php#L110-L126 + * @see WooCommerce/woocommerce#31518 + * + * @param bool $has_template Whether or not the block template was located. + * @param string $template_name Which template are we looking for. + * + * @return bool Whether a template with that name exists + */ + public function maybe_has_template( $has_template, $template_name ) { + if ( $has_template ) { + return $has_template; + } + + return BlockTemplateUtils::theme_has_template( $template_name ); + } } From e94224f41d1644e110aa223308ee6b706848543d Mon Sep 17 00:00:00 2001 From: Lucio Giannotta Date: Tue, 28 Dec 2021 19:36:33 +0100 Subject: [PATCH 10/10] Revert "Add template check logic to `woocommerce_has_block_template` filter" This reverts commit 855ae2e4523e09d09766c7845d46f0cd2547f3dc. --- src/BlockTemplatesController.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index e283547cd68..be1fa2ea7da 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -57,7 +57,6 @@ protected function init() { add_action( 'template_redirect', array( $this, 'render_block_template' ) ); add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 ); - add_filter( 'woocommerce_has_block_template', array( $this, 'maybe_has_template' ), 10, 2 ); } /** @@ -439,27 +438,4 @@ public function render_block_template() { } } - /** - * Checks alternative paths for block templates - * - * This function is supposed to be hooked to the `woocommerce_has_block_template` filter. - * Since Gutenberg 12.1.0, directory names conventions for block templates have changed, - * however, WooCommerce still doesn't support that. Because of that, we patch the support - * by using our own checking functionality here. - * - * @see woocommerce/includes/class-wc-template-loader.php#L110-L126 - * @see WooCommerce/woocommerce#31518 - * - * @param bool $has_template Whether or not the block template was located. - * @param string $template_name Which template are we looking for. - * - * @return bool Whether a template with that name exists - */ - public function maybe_has_template( $has_template, $template_name ) { - if ( $has_template ) { - return $has_template; - } - - return BlockTemplateUtils::theme_has_template( $template_name ); - } }