Make WordPress Core

Opened 20 months ago

Last modified 19 months 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
20 months ago

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

#2 @markparnell
19 months 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.