[wp-trac] [WordPress Trac] #56519: Inner blocks serialization bug in serialize_block function

WordPress Trac noreply at wordpress.org
Tue Sep 6 08:41:34 UTC 2022


#56519: Inner blocks serialization bug in serialize_block function
-------------------------------------------+-----------------------------
 Reporter:  saqibsarwar                    |      Owner:  (none)
     Type:  defect (bug)                   |     Status:  new
 Priority:  normal                         |  Milestone:  Awaiting Review
Component:  General                        |    Version:  6.0.1
 Severity:  normal                         |   Keywords:  has-patch
  Focuses:  performance, coding-standards  |
-------------------------------------------+-----------------------------
 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
 <?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
         );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56519>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list