mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
REST API: Support the JSON Schema pattern keyword.
Props jason_the_adams, birgire, sorenbronsted. Fixes #44949. git-svn-id: https://develop.svn.wordpress.org/trunk@47810 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1382,6 +1382,14 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $args['pattern'] ) ) {
|
||||
$pattern = str_replace( '#', '\\#', $args['pattern'] );
|
||||
if ( ! preg_match( '#' . $pattern . '#u', $value ) ) {
|
||||
/* translators: 1: Parameter, 2: Pattern. */
|
||||
return new WP_Error( 'rest_invalid_pattern', sprintf( __( '%1$s does not match pattern %2$s.' ), $param, $args['pattern'] ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $args['format'] ) ) {
|
||||
|
||||
Reference in New Issue
Block a user