Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Hooks: Avoid processing empty content for loaded templates #54719

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/compat/wordpress-6.4/block-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
Loading