Skip to content

Block Supports: Prevent fatal error in WP_Duotone when the duotone …#10883

Closed
jorgefilipecosta wants to merge 2 commits intoWordPress:trunkfrom
jorgefilipecosta:fix/duotone-faltal
Closed

Block Supports: Prevent fatal error in WP_Duotone when the duotone …#10883
jorgefilipecosta wants to merge 2 commits intoWordPress:trunkfrom
jorgefilipecosta:fix/duotone-faltal

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

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.json is an array (custom colors) instead of a string (preset reference).

Problem

A fatal error occurs in WP_Duotone::get_slug_from_attribute() when $duotone_attr is an array:

Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in wp-includes/class-wp-duotone.php

This happens when a theme's theme.json defines duotone with an array of colors (custom colors) rather than a preset reference 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

Testing

  1. Apply a theme with a theme.json that has an array value for duotone (custom colors)
  2. Verify no fatal error occurs
  3. Run PHPUnit tests: phpunit tests/phpunit/tests/block-supports/duotone.php

Props xavier-lc for the Gutenberg PR.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 7, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 7, 2026

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61603
GitHub commit: edd6885

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants