Skip to content

Fix rich-text attribute type normalization in WP_Block_Type#11985

Draft
USERSATOSHI wants to merge 2 commits into
WordPress:trunkfrom
USERSATOSHI:fix/rich-text-schema-validation
Draft

Fix rich-text attribute type normalization in WP_Block_Type#11985
USERSATOSHI wants to merge 2 commits into
WordPress:trunkfrom
USERSATOSHI:fix/rich-text-schema-validation

Conversation

@USERSATOSHI
Copy link
Copy Markdown

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

Normalize rich-text block attribute type to string in WP_Block_Type::set_props()

Block attributes with type: "rich-text" (used in block.json for the editor) are not valid JSON Schema types. When WP_Block_Type::prepare_attributes_for_render() calls rest_validate_value_from_schema(), the unrecognised rich-text type triggers a _doing_it_wrong() notice:

The "type" schema keyword for content can only be one of the built-in types: array, object, string, number, integer, boolean, and null.
This affects all core blocks that define attributes as rich-text: paragraph, heading, list-item, image (caption), embed (caption), quote, pullquote, verse, code, preformatted, table, gallery, button, file, video, audio, details, and accordion-heading.

Changes in this PR:

  1. src/wp-includes/class-wp-block-type.php — In set_props(), normalise rich-text to string at block registration time. This runs once (not per-render) and occurs before the register_block_type_args filter, so plugins can still override if needed.
  2. tests/phpunit/tests/blocks/wpBlockType.php — Added a richtext attribute case to test_prepare_attributes() to verify that rich-text typed attributes pass validation without triggering _doing_it_wrong.

Related: Gutenberg issue WordPress/gutenberg#72180


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

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

@USERSATOSHI USERSATOSHI marked this pull request as ready for review May 27, 2026 13:09
@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 tusharbharti.

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

@USERSATOSHI USERSATOSHI marked this pull request as draft May 27, 2026 13:15
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