[wp-trac] [WordPress Trac] #45316: parse_blocks returns an empty object in 'attrs' when there are no attributes
WordPress Trac
noreply at wordpress.org
Fri Nov 9 10:19:22 UTC 2018
#45316: parse_blocks returns an empty object in 'attrs' when there are no
attributes
--------------------------+-----------------------------
Reporter: Chouby | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 5.0
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45316>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list