[wp-trac] [WordPress Trac] #64612: WP_Duotone: Fatal error when duotone attribute is an array instead of a string
WordPress Trac
noreply at wordpress.org
Sat Feb 7 11:40:56 UTC 2026
#64612: WP_Duotone: Fatal error when duotone attribute is an array instead of a
string
------------------------------+--------------------------------------
Reporter: jorgefilipecosta | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: trunk
Severity: normal | Keywords: has-patch has-unit-tests
Focuses: |
------------------------------+--------------------------------------
A fatal error occurs in `WP_Duotone::get_slug_from_attribute()` when the
`$duotone_attr` parameter is an array (custom colors) instead of a string
(preset reference).
== Description ==
When a theme's `theme.json` defines duotone with an array of custom colors
rather than a preset reference string, a fatal error is thrown:
{{{
Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must
be of type string, array given in wp-includes/class-wp-duotone.php
}}}
The duotone attribute can be:
1. A preset reference string: `var:preset|duotone|blue-orange` or
`var(--wp--preset--duotone--blue-orange)`
2. An array of custom colors: `['#000000', '#ffffff']`
3. A CSS string: `unset`
The current code assumes the attribute is always a string when checking
for presets, which causes a fatal error when an array of custom colors is
passed.
== Steps to Reproduce ==
1. Create a theme with a `theme.json` that uses an array value for
duotone:
{{{
{
"styles": {
"blocks": {
"core/image": {
"filter": {
"duotone": ["#000000", "#ffffff"]
}
}
}
}
}
}}}
2. Activate the theme
3. Load any page - fatal error occurs
== Expected Results ==
No fatal error. Custom duotone colors should be processed correctly.
== Actual Results ==
Fatal error is thrown due to `preg_match()` receiving an array instead of
a string.
== Solution ==
Add type checks to ensure `$duotone_attr` is a string before attempting to
parse it:
1. `get_slug_from_attribute()` - Returns empty string for non-string input
2. `is_preset()` - Returns false for non-string input
3. `get_all_global_style_block_names()` - Skips non-string duotone
attributes
== Related ==
* Gutenberg PR: https://github.com/WordPress/gutenberg/pull/75283
* Props: xavier-lc
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64612>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list