REST API: Support the multipleOf JSON Schema keyword.
Props yakimun. Fixes #51022. Built from https://develop.svn.wordpress.org/trunk@49063 git-svn-id: http://core.svn.wordpress.org/trunk@48825 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6bdbb8b25c
commit
bed5797cf6
|
@ -1552,6 +1552,7 @@ function rest_stabilize_value( $value ) {
|
|||
* Support the "minItems", "maxItems" and "uniqueItems" keywords for arrays.
|
||||
* Validate required properties.
|
||||
* @since 5.6.0 Support the "minProperties" and "maxProperties" keywords for objects.
|
||||
* Support the "multipleOf" keyword for numbers and integers.
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
* @param array $args Schema array to use for validation.
|
||||
|
@ -1691,9 +1692,16 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( in_array( $args['type'], array( 'integer', 'number' ), true ) && ! is_numeric( $value ) ) {
|
||||
/* translators: 1: Parameter, 2: Type name. */
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) );
|
||||
if ( in_array( $args['type'], array( 'integer', 'number' ), true ) ) {
|
||||
if ( ! is_numeric( $value ) ) {
|
||||
/* translators: 1: Parameter, 2: Type name. */
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $args['multipleOf'] ) && fmod( $value, $args['multipleOf'] ) !== 0.0 ) {
|
||||
/* translators: 1: Parameter, 2: Multiplier. */
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be a multiple of %2$s.' ), $param, $args['multipleOf'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'integer' === $args['type'] && ! rest_is_integer( $value ) ) {
|
||||
|
@ -2298,6 +2306,7 @@ function rest_get_endpoint_args_for_schema( $schema, $method = WP_REST_Server::C
|
|||
'maximum',
|
||||
'exclusiveMinimum',
|
||||
'exclusiveMaximum',
|
||||
'multipleOf',
|
||||
'minLength',
|
||||
'maxLength',
|
||||
'pattern',
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.6-alpha-49062';
|
||||
$wp_version = '5.6-alpha-49063';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue