Make WordPress Core

Opened 2 years ago

#56593 new feature request

Post meta validation error messages are not helpful to end users

Reported by: andrewleap's profile andrewleap Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.0.2
Component: REST API Keywords: 2nd-opinion
Focuses: rest-api Cc:

Description

The meta error messages generated by the validate callback are not helpful to the end user.

For example, if we register a meta field with the following:

register_post_meta(
	$post_type,
	'author_url',
	array(
			'type'             => 'string',
			'show_in_rest'     => array(
		   	     'single'           => true,
			     'schema'           => array(
			     'type'             => 'string',
			     'pattern'          => 'https:\/\/.+',
			),
		)
	)
);

An incorrectly formatted field would yield the following error message in the Gutenberg editor:

Updating failed. meta.author_url does not match pattern https:\/\/.+.

As far as I can tell, the only way I can see currently to filter the message is to crudely hook into rest_post_dispatch and string replace the error message.

I may be wrong. Perhaps there is some way to conveniently do this on the client side with the notice date store selectors / actions, but since the meta fields are registered server side, it seems like it would be more convenient to filter the output of rest_validate_value_from_schema to customize the error messages

I'd like to request a rest_validate_value_from_schema filter.

Change History (0)

Note: See TracTickets for help on using tickets.