From 6bd222805ba1fecab71a520d4da2f087827f8473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 9 Dec 2021 10:35:32 +0100 Subject: [PATCH] Fix reverting WC templates (#5342) --- src/BlockTemplatesController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index 0e47f2de912..119acd71ae2 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -55,7 +55,7 @@ public function __construct() { */ protected function init() { add_action( 'template_redirect', array( $this, 'render_block_template' ) ); - add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); + 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 ); } @@ -82,24 +82,24 @@ public function maybe_return_blocks_template( $template, $id, $template_type ) { list( , $slug ) = $template_name_parts; // Remove the filter at this point because if we don't then this function will infinite loop. - remove_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); + remove_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); // 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 = gutenberg_get_block_template( $id, $template_type ); if ( null !== $maybe_template ) { - add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); + add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); return $maybe_template; } // 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_template', array( $this, 'get_single_block_template' ), 10, 3 ); + add_filter( 'get_block_file_template', array( $this, 'get_single_block_template' ), 10, 3 ); $maybe_template = gutenberg_get_block_template( 'woocommerce//' . $slug, $template_type ); // Re-hook this function, it was only unhooked to stop recursion. - add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); - remove_filter( 'get_block_template', array( $this, 'get_single_block_template' ), 10, 3 ); + add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 ); + remove_filter( 'get_block_file_template', array( $this, 'get_single_block_template' ), 10, 3 ); if ( null !== $maybe_template ) { return $maybe_template; }