Skip to content

Editor: Ignore theme.json values of unexpected types - #14190

Open
ramonjd wants to merge 1 commit into
WordPress:trunkfrom
ramonjd:fix/theme-json-non-string-values
Open

ramonjd wants to merge 1 commit into
WordPress:trunkfrom
ramonjd:fix/theme-json-non-string-values

Conversation

@ramonjd

@ramonjd ramonjd commented Oct 11, 2026

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/66286

Backports WordPress/gutenberg#84523.

What

Stops WP_Theme_JSON from throwing fatal TypeErrors when theme.json or global styles data contains values of the wrong type.

Why

The Gutenberg report came from a live site where every front-end page fatalled:

PHP Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given
#1 WP_Theme_JSON_Gutenberg::process_blocks_custom_css(Array, 'a:where(:not(.w...')
#2 WP_Theme_JSON_Gutenberg->get_styles_for_block(Array)

sanitize() keeps schema leaves such as css and spacingScale whatever their type, so an array css value reaches explode() in process_blocks_custom_css(). The same gap fatals in a few other places.

What changed

Values of unexpected types are now ignored instead of crashing:

  • css that isn't a string produces no output (the reported crash).
  • ref that isn't a string is ignored.
  • A spacingScale that isn't an array, or a spacingScale.unit that isn't a string, is ignored.
  • Shared block style variations that aren't arrays, and blockTypes items that aren't strings, are skipped.

Valid data is unaffected.

Each case has a test. All nine new cases fail on trunk with a TypeError.

Prevents `WP_Theme_JSON` from throwing fatal `TypeError`s when theme.json or global styles data contains values of the wrong type. Sanitization keeps schema leaves such as `css` and `spacingScale` whatever their type, so, for example, an array `css` value reached `explode()` in `process_blocks_custom_css()`.

Values of unexpected types are now ignored: non-string `css` and `ref` values, a non-array `spacingScale` or non-string `spacingScale.unit`, shared block style variations that are not arrays, and `blockTypes` items that are not strings.

Backports WordPress/gutenberg#84523.

See #66286.
@github-actions

Copy link
Copy Markdown

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 ramonopoly.

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

@ramonjd ramonjd self-assigned this Oct 11, 2026
@github-actions

Copy link
Copy Markdown

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

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant