[wp-trac] [WordPress Trac] #59168: Block API: Unnecessary JSON decoding in block parser
WordPress Trac
noreply at wordpress.org
Tue Aug 22 17:31:38 UTC 2023
#59168: Block API: Unnecessary JSON decoding in block parser
--------------------------+-----------------------------
Reporter: dlh | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 5.0
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
The `WP_Block_Parser::$empty_attrs` property is initialized with:
`$this->empty_attrs = json_decode( '{}', true );`
which produces an empty array. `json_decode()` isn't needed to create this
array; a plain `array()` is equivalent. See https://3v4l.org/M1Qie.
Some background that I can find: This logic predates the original
Gutenberg merge in WordPress 5.0. It was introduced in
[https://github.com/WordPress/gutenberg/pull/10107/files#diff-
2e3a0202f616f381aeccb56ae15fb72eedd102ddb9e87c223c7eaa248a4d7732R372-R378
GB PR 10107]. In the original implementation, the JSON was decoded into an
object, not an array. It was updated to its current form in
[https://github.com/WordPress/gutenberg/pull/11434/ GB PR 11434].
In the linked PR, I've removed the function call from the property
initialization. I've also made a couple fixes to the documentation. First,
I removed the inline comment about creating "an empty associative array,"
which I think was targeted at the change in GB PR 10107 and made less
relevant by the update in PR 11434. Second, to update some `@since` tags
to WordPress core versions, not Gutenberg.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59168>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list