[wp-trac] [WordPress Trac] #56593: Post meta validation error messages are not helpful to end users
WordPress Trac
noreply at wordpress.org
Sat Sep 17 07:06:47 UTC 2022
#56593: Post meta validation error messages are not helpful to end users
-----------------------------+-----------------------------
Reporter: andrewleap | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 6.0.2
Severity: normal | Keywords: 2nd-opinion
Focuses: rest-api |
-----------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56593>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list