Block Supports: Prevent fatal error in WP_Duotone when the duotone …#10883
Block Supports: Prevent fatal error in WP_Duotone when the duotone …#10883jorgefilipecosta wants to merge 2 commits intoWordPress:trunkfrom
WP_Duotone when the duotone …#10883Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
westonruter
left a comment
There was a problem hiding this comment.
See suggestions in my review of the Gutenberg PR: WordPress/gutenberg#75283 (review)
…attribute is an array. Adds type checks to `get_slug_from_attribute()`, `is_preset()`, and `get_all_global_style_block_names()` to handle cases where the duotone attribute is an array of custom colors instead of a preset reference string. Props xavier-lc. Fixes #64612.
1973d34 to
79443de
Compare
Trac ticket
https://core.trac.wordpress.org/ticket/64612
Description
This PR backports the fix from Gutenberg PR #75283 to prevent a fatal error when the duotone attribute in
theme.jsonis an array (custom colors) instead of a string (preset reference).Problem
A fatal error occurs in
WP_Duotone::get_slug_from_attribute()when$duotone_attris an array:This happens when a theme's
theme.jsondefines duotone with an array of colors (custom colors) rather than a preset reference string.Solution
Add type checks to ensure
$duotone_attris a string before attempting to parse it:get_slug_from_attribute()- Returns empty string for non-string inputis_preset()- Returns false for non-string inputget_all_global_style_block_names()- Skips non-string duotone attributesTesting
theme.jsonthat has an array value for duotone (custom colors)phpunit tests/phpunit/tests/block-supports/duotone.phpProps xavier-lc for the Gutenberg PR.