Make WordPress Core


Ignore:
Timestamp:
06/07/2020 10:40:16 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support the (min|max)Items JSON Schema keywords.

A future commit will add support for the uniqueItems keyword.

Props sorenbronsted.
See #48821.

File:
1 edited

Legend:

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

    r47849 r47923  
    12511251 *              Support the "minLength", "maxLength" and "pattern" keywords for strings.
    12521252 *              Validate required properties.
     1253 *              Support the "minItems" and "maxItems" keywords for arrays.
    12531254 *
    12541255 * @param mixed  $value The value to validate.
     
    12871288                return $is_valid;
    12881289            }
     1290        }
     1291
     1292        if ( isset( $args['minItems'] ) && count( $value ) < $args['minItems'] ) {
     1293            /* translators: 1: Parameter, 2: number. */
     1294            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at least %2$s items.' ), $param, number_format_i18n( $args['minItems'] ) ) );
     1295        }
     1296
     1297        if ( isset( $args['maxItems'] ) && count( $value ) > $args['maxItems'] ) {
     1298            /* translators: 1: Parameter, 2: number. */
     1299            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at most %2$s items.' ), $param, number_format_i18n( $args['maxItems'] ) ) );
    12891300        }
    12901301    }
Note: See TracChangeset for help on using the changeset viewer.