Opened 4 weeks ago
Closed 4 weeks ago
#66286 closed enhancement (fixed)
Global Styles: Ignore theme.json values of unexpected types
| Reported by: | ramonopoly | Owned by: | ramonopoly |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Themes | Version: | 6.2 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
Tracks the backport of https://github.com/WordPress/gutenberg/pull/84523 and https://github.com/WordPress/gutenberg/pull/84529
AI generated content (the main suspect) creating custom CSS for theme.json can cause PHP fatals.
process_blocks_custom_css() tries to explode an non-string ($css).
Reported on a live site:
`
PHP Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given in lib/class-wp-theme-json-gutenberg.php:2085
#1 WP_Theme_JSON_Gutenberg::process_blocks_custom_css(Array, 'a:where(:not(.w...')
#2 WP_Theme_JSON_Gutenberg->get_styles_for_block(Array)
`
Change History (3)
This ticket was mentioned in PR #14190 on WordPress/wordpress-develop by @ramonopoly.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Backports https://github.com/WordPress/gutenberg/pull/84523.
What
Stops
WP_Theme_JSONfrom throwing fatalTypeErrors 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:
sanitize()keeps schema leaves such ascssandspacingScalewhatever their type, so an arraycssvalue reachesexplode()inprocess_blocks_custom_css(). The same gap fatals in a few other places.What changed
Values of unexpected types are now ignored instead of crashing:
cssthat isn't a string produces no output (the reported crash).refthat isn't a string is ignored.spacingScalethat isn't an array, or aspacingScale.unitthat isn't a string, is ignored.blockTypesitems 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.