From 14a45a438031b1d3e6d356617299700dd28216cd Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 21 Dec 2021 11:55:51 +0100 Subject: [PATCH] fix not found template for the template editor (https://github.com/woocommerce/woocommerce-blocks/pull/5425) --- .../src/BlockTemplatesController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index a631eb4b918..48fae793464 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -92,9 +92,10 @@ class BlockTemplatesController { // Check if the theme has a saved version of this template before falling back to the woo one. Please note how // the slug has not been modified at this point, we're still using the default one passed to this hook. - $maybe_template = function_exists( 'get_block_template' ) ? - get_block_template( $id, $template_type ) : - gutenberg_get_block_template( $id, $template_type ); + $maybe_template = function_exists( 'gutenberg_get_block_template' ) ? + gutenberg_get_block_template( $id, $template_type ) : + get_block_template( $id, $template_type ); + if ( null !== $maybe_template ) { add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); return $maybe_template; @@ -103,9 +104,9 @@ class BlockTemplatesController { // Theme-based template didn't exist, try switching the theme to woocommerce and try again. This function has // been unhooked so won't run again. add_filter( 'get_block_file_template', array( $this, 'get_single_block_template' ), 10, 3 ); - $maybe_template = function_exists( 'get_block_template' ) ? - get_block_template( 'woocommerce//' . $slug, $template_type ) : - gutenberg_get_block_template( 'woocommerce//' . $slug, $template_type ); + $maybe_template = function_exists( 'gutenberg_get_block_template' ) ? + gutenberg_get_block_template( 'woocommerce//' . $slug, $template_type ) : + get_block_template( 'woocommerce//' . $slug, $template_type ); // Re-hook this function, it was only unhooked to stop recursion. add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );