Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#56519 new defect (bug)

Inner blocks serialization bug in serialize_block function

Reported by: saqibsarwar's profile saqibsarwar Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3.1
Component: Editor Keywords: needs-patch
Focuses: Cc:

Description

Hi,

The serialize_block function https://developer.wordpress.org/reference/functions/serialize_block/ fails when the number of inner blocks increases.

The following custom function solved it for me.

<?php
function custom_serialize_block( $block ) {
        $block_content = '';

        foreach ( $block['innerContent'] as $chunk ) {
                if ( is_string( $chunk ) ) {
                        $block_content .= $chunk;
                } else {
                        foreach ( $block['innerBlocks'] as $inner_block ) {
                                $block_content .= custom_serialize_block( $inner_block );
                        }
                }
        }

        if ( ! is_array( $block['attrs'] ) ) {
                $block['attrs'] = [];
        }

        return get_comment_delimited_block_content(
                $block['blockName'],
                $block['attrs'],
                $block_content
        );
}

Change History (2)

#1 @dingo_d
2 years ago

  • Focuses performance coding-standards removed
  • Keywords needs-patch added; has-patch removed

#2 @markparnell
2 years ago

  • Component changed from General to Editor
  • Version changed from 6.0.1 to 5.3.1
Note: See TracTickets for help on using tickets.