WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 11 months ago

Last modified 11 months ago

#45316 closed defect (bug) (reported-upstream)

parse_blocks returns an empty object in 'attrs' when there are no attributes

Reported by: Chouby Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0
Component: Editor Keywords:
Focuses: Cc:
PR Number:

Description

According to the inline documentation of WP_Block_Parser, parse_blocks should return arrays not objects, all attributes are arrays. See https://core.trac.wordpress.org/browser/branches/5.0/src/wp-includes/class-wp-block-parser.php#L124

Parsing

<!-- wp:paragraph -->
<p>First paragraph</p>
<!-- /wp:paragraph -->

returns

Array
(
    [0] => Array
        (
            [blockName] => core/paragraph
            [attrs] => stdClass Object
                (
                )

            [innerBlocks] => Array
                (
                )

            [innerHTML] => 
<p>First paragraph</p>

        )

)

If the block has no attribute, [attrs] is an empty object while, according to the documentation, we would expect an empty array.

In other cases, when the block includes attributes or when parsing a free form text, [attrs] is, as expected, an array.

Change History (3)

#1 @swissspidy
12 months ago

Looks like there‘s an open PR for this: https://github.com/WordPress/gutenberg/pull/11434

#2 @matveb
11 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Closing as this was addressed upstream.

#3 @ocean90
11 months ago

  • Milestone Awaiting Review deleted
  • Resolution changed from fixed to reported-upstream
Note: See TracTickets for help on using tickets.