Make WordPress Core


Ignore:
Timestamp:
09/27/2020 07:01:18 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support the multipleOf JSON Schema keyword.

Props yakimun.
Fixes #51022.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r49054 r49063  
    15531553 *              Validate required properties.
    15541554 * @since 5.6.0 Support the "minProperties" and "maxProperties" keywords for objects.
     1555 *              Support the "multipleOf" keyword for numbers and integers.
    15551556 *
    15561557 * @param mixed  $value The value to validate.
     
    16921693    }
    16931694
    1694     if ( in_array( $args['type'], array( 'integer', 'number' ), true ) && ! is_numeric( $value ) ) {
    1695         /* translators: 1: Parameter, 2: Type name. */
    1696         return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) );
     1695    if ( in_array( $args['type'], array( 'integer', 'number' ), true ) ) {
     1696        if ( ! is_numeric( $value ) ) {
     1697            /* translators: 1: Parameter, 2: Type name. */
     1698            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) );
     1699        }
     1700
     1701        if ( isset( $args['multipleOf'] ) && fmod( $value, $args['multipleOf'] ) !== 0.0 ) {
     1702            /* translators: 1: Parameter, 2: Multiplier. */
     1703            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be a multiple of %2$s.' ), $param, $args['multipleOf'] ) );
     1704        }
    16971705    }
    16981706
     
    22992307        'exclusiveMinimum',
    23002308        'exclusiveMaximum',
     2309        'multipleOf',
    23012310        'minLength',
    23022311        'maxLength',
Note: See TracChangeset for help on using the changeset viewer.