Make WordPress Core

Opened 18 months ago

Last modified 2 months ago

#61406 new defect (bug)

Heading block attribute type issue

Reported by: metaphorcreations's profile metaphorcreations Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.5.4
Component: Posts, Post Types Keywords: needs-test-info
Focuses: Cc:

Description

The Heading block is still using rich-text as the type for the content attribute and I am seeing the following warning:

Notice: Function rest_validate_value_from_schema was called incorrectly. The "type" schema keyword for content can only be one of the built-in types: array, object, string, number, integer, boolean, and null.

Change History (9)

#1 @mai21
18 months ago

  • Keywords needs-testing-info added

@metaphorcreations Thanks for reporting the issue. Can you please provide reproducible steps?

Note: Using https://wordpress.org/plugins/test-reports/ can help to add the needed info. Thanks

This ticket was mentioned in Slack in #core-test by mai21. View the logs.


18 months ago

#3 @metaphorcreations
18 months ago

@mai21 I have a custom plugin that works with Gravity Forms and uses blocks to design email templates. This error occurs When a form is submitted and the blocks are rendered for the notifications. I haven't run into the issue when just using blocks on pages/posts, etc... So, it's quite a few steps to replicate.

But, I do know that many core blocks that WordPress loads from the wp-includes/blocks/blocks-json.php file contain "rich-text" types, which is causing the issue for my plugin.

Is there a reason why core block attributes are still using the "rich-text" type when it's not supported anymore?

The type field MUST be one of the following:

null
boolean
object
array
string
integer
number (same as integer)

#5 @wordpressdotorg
7 months ago

  • Keywords needs-test-info added; needs-testing-info removed

#6 @Mamaduka
4 months ago

Hi, @metaphorcreations

Can you create an issue on the Gutenberg repo with reproduction steps? Link: https://github.com/WordPress/gutenberg/issues/new

The rich-text is a valid block attribute type.

#7 @andfinally
3 months ago

We are getting this issue in unit tests for RSS feeds. I believe this problem appeared after the WordPress 6.8 update.

When we include the markup of an image block in a test post, example below, the test fails, and we get the notice:

Notice: Function rest_validate_value_from_schema was called <strong>incorrectly</strong>. The "type" schema keyword for caption can only be one of the built-in types: array, object, string, number, integer, boolean, and null. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 5.5.0.) in /tmp/wordpress/wp-includes/functions.php on line 6114
<!-- wp:image {"url":"http://example.org/wp-content/uploads/2022/03/55038451-0-image-a-2_1646636766274.jpg?quality=90\u0026strip=all","caption":"Lorem ipsum","id":10853156,"sizeSlug":"full","linkDestination":"none"} -->

It looks like the following call stack is being run:

\do_blocks
-> \render_block
-> \WP_Block::render
-> \WP_Block::__get
-> \WP_Block_Type::prepare_attributes_for_render
-> \rest_validate_value_from_schema

When rest_validate_value_from_schema gets to the caption, the parameters are:

Value: Lorem ipsum
Schema: Array
(
    [type] => rich-text
    [source] => rich-text
    [selector] => figcaption
    [role] => content
)

This is validating the post content against the data types defined in the block.json file for the core/image block. There, rich-text is an acceptable type, as @Mamaduka says. But rest_validate_value_from_schema expects string, and complains.

To me, this doesn't look like a Gutenberg bug but an issue in the PHP.

It does seem weird that we validate block attributes against the types expected in a REST schema – the context is different. But apparently \WP_Block_Type::prepare_attributes_for_render has been calling rest_validate_value_from_schema since before WP 5.6.

Last edited 3 months ago by andfinally (previous) (diff)

#8 @andfinally
3 months ago

The rich-text type was added to the core image block.json in commit https://github.com/WordPress/WordPress/commit/1de40f71be71a2ae45fb615e06a2279b8ad363a0, which brought in Gutenberg 16.7 RC2. A bunch of other blocks also now have rich-text as the data type for attributes like caption.

The docs don't list rich-text as an allowed data type for block attributes: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation. rest_validate_value_from_schema follows this list. It validates attributes against this array.

$allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' );

The caption attribute of images is now rich-text, so blocks with this attribute fail the validation.

Maybe we need to stop using rest_validate_value_from_schema for non-REST contexts, or add a filter hook to it which allows developers to adjust the allowed types when needed.

Last edited 3 months ago by andfinally (previous) (diff)

#9 @andfinally
2 months ago

I have created https://github.com/WordPress/gutenberg/issues/72180 for this. It seems like an issue between WordPress and Gutenberg. Gutenberg has defined data types for image captions which WordPress block rendering doesn't expect.

Note: See TracTickets for help on using tickets.