From 682c53f02a2854185715e29b13f01415784e1c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Zi=C3=B3=C5=82kowski?= Date: Fri, 22 Sep 2023 11:13:53 +0200 Subject: [PATCH] Block Hooks: Avoid processing empty content for loaded templates --- lib/compat/wordpress-6.4/block-hooks.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.4/block-hooks.php b/lib/compat/wordpress-6.4/block-hooks.php index 6fd7d4a4af1b4..05c146ebe75c9 100644 --- a/lib/compat/wordpress-6.4/block-hooks.php +++ b/lib/compat/wordpress-6.4/block-hooks.php @@ -247,7 +247,7 @@ function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_blo */ function gutenberg_parse_and_serialize_block_templates( $query_result ) { foreach ( $query_result as $block_template ) { - if ( 'custom' === $block_template->source ) { + if ( empty( $block_template->content ) || 'custom' === $block_template->source ) { continue; } $blocks = parse_blocks( $block_template->content ); @@ -270,6 +270,9 @@ function gutenberg_parse_and_serialize_block_templates( $query_result ) { * @param WP_Block_Template|null $block_template The found block template, or null if there is none. */ function gutenberg_parse_and_serialize_blocks( $block_template ) { + if ( empty( $block_template->content ) ) { + return $block_template; + } $blocks = parse_blocks( $block_template->content ); $block_template->content = gutenberg_serialize_blocks( $blocks );