Skip to content

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

Open
im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/backport-for-80501
Open

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

Conversation

@im3dabasia

@im3dabasia im3dabasia commented Jul 24, 2026

Copy link
Copy Markdown

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

What?

Backport PR of WordPress/gutenberg#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.

@im3dabasia
im3dabasia marked this pull request as ready for review July 30, 2026 11:35
@github-actions

github-actions Bot commented Jul 30, 2026

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

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

@im3dabasia
im3dabasia force-pushed the feat/backport-for-80501 branch from 9d06885 to 0a6edad Compare July 30, 2026 11:59

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Faithful backport. Nothing to fix in the code. Just needs a track ticket + ticket number in the tests.

Thanks for getting to this!

I reckon it's okay to target the 7.2 milestone for this, what you do think?

Comment thread tests/phpunit/tests/block-supports/layout.php
@im3dabasia

Copy link
Copy Markdown
Author

Thanks for the review!

I reckon it's okay to target the 7.2 milestone for this, what you do think?

Yes, this should be fine.

If you have a moment, would you mind creating the Trac ticket for this issue? I'm not sure why, but I don't seem to have the Create Ticket button on my Trac screen. Reference

@ramonjd

ramonjd commented Jul 31, 2026

Copy link
Copy Markdown
Member

Here it is!

https://core.trac.wordpress.org/ticket/65774

Comment thread tests/phpunit/tests/block-supports/layout.php
Comment thread tests/phpunit/tests/block-supports/layout.php
Comment thread tests/phpunit/tests/block-supports/layout.php
Comment thread tests/phpunit/tests/block-supports/layout.php
Comment thread tests/phpunit/tests/block-supports/layout.php
@im3dabasia

Copy link
Copy Markdown
Author

Thanks @ramonjd for the continued efforts to move this PR forward.

I've updated the tests to include the Core ticket. I think this is in good shape for us to ship in WordPress 7.2.

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.

2 participants