Skip to content

Block Supports: Guard against non-string attribute values to avoid fatal errors (Backport for GB #80501)#12674

Draft
im3dabasia wants to merge 1 commit into
WordPress:trunkfrom
im3dabasia:feat/backport-for-80501
Draft

Block Supports: Guard against non-string attribute values to avoid fatal errors (Backport for GB #80501)#12674
im3dabasia wants to merge 1 commit into
WordPress:trunkfrom
im3dabasia:feat/backport-for-80501

Conversation

@im3dabasia

Copy link
Copy Markdown

Trac ticket:

What?

Backport PR of #80494

Guards block supports callbacks against non-string (and other wrong-typed) attribute values so they no longer cause fatalTypeErrors on the front end. (Block support is handled in a this PR.)

Why?

block.json / theme.json types aren't enforced at render time, so wrong-typed values from hand-editing, imports, or AI-generated content reach strict PHP ops (explode, preg_match, str_contains, addcslashes, parse_url, array_column, wp_strip_all_tags, array offsets) and fatal in PHP 8+.

How?

Following the existing idiom guard with is_string() / is_array() / is_scalar() before each strict op and treat a wrong-typed value as absent.

Testing Instructions

Existing tests should pass

Testing Instructions for Keyboard

N/A — no UI changes.

Use of AI Tools

Claude Code

@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant