[wp-trac] [WordPress Trac] #62966: PHP output of get_comment_delimited_block_content does not match Gutenberg JS output

WordPress Trac noreply at wordpress.org
Fri Feb 14 19:09:58 UTC 2025


#62966: PHP output of get_comment_delimited_block_content does not match Gutenberg
JS output
--------------------------+-----------------------------
 Reporter:  kevinfodness  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  trunk
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 The `get_comment_delimited_block_content` function (in PHP) does not
 produce the same output as block content created in Gutenberg.

 For example, if I create a new post using the block editor and add a
 paragraph block with the text "This is a paragraph." and save it, the
 following markup gets saved to `post_content`:

 {{{
 <!-- wp:paragraph -->
 <p>This is a paragraph.</p>
 <!-- /wp:paragraph -->
 }}}

 However, if I attempt to do the same thing using the
 `get_comment_delimited_block_content`:

 {{{
 #!php
 get_comment_delimited_block_content( 'paragraph', [], '<p>This is a
 paragraph.</p>' );
 }}}

 the output lacks the line breaks:

 {{{
 <!-- wp:paragraph --><p>This is a paragraph.</p><!-- /wp:paragraph -->
 }}}

 This presents problems for PHP code that produces Gutenberg markup (e.g.,
 in data migrations) because what is saved to the database by using this
 function is not the same as what would be saved if the user edited the
 content directly in Gutenberg, which may have unintentional side effects
 down the line if code expects there to be line breaks after the opening
 comment and before the closing comment as it is written by Gutenberg JS.

 The output of `get_comment_delimited_block_content` in PHP should match
 what is generated by Gutenberg's JavaScript. At a minimum, the function
 should be modified so that when block contents are provided, there are
 line breaks after the opening comment and before the closing comment, but
 there may be other areas where the output doesn't match exactly that
 should be brought into parity as well.

 (Note: While this applies to block editor functionality, the code in
 question lives in wp-includes/blocks.php which is part of Core, not the
 Gutenberg GitHub repo.)

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


More information about the wp-trac mailing list