#45316 closed defect (bug) (reported-upstream)
parse_blocks returns an empty object in 'attrs' when there are no attributes
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 5.0 |
| Component: | Editor | Keywords: | |
| Focuses: | Cc: |
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)
Note: See
TracTickets for help on using
tickets.
Looks like there‘s an open PR for this: https://github.com/WordPress/gutenberg/pull/11434