Make WordPress Core


Ignore:
Timestamp:
09/26/2020 06:18:53 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support the minProperties and maxProperties JSON Schema keywords.

Props yakimun.
Fixes #51023.

File:
1 edited

Legend:

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

    r48951 r49053  
    15521552 *              Support the "minItems", "maxItems" and "uniqueItems" keywords for arrays.
    15531553 *              Validate required properties.
     1554 * @since 5.7.0 Support the "minProperties" and "maxProperties" keywords for objects.
    15541555 *
    15551556 * @param mixed  $value The value to validate.
     
    16621663                }
    16631664            }
     1665        }
     1666
     1667        if ( isset( $args['minProperties'] ) && count( $value ) < $args['minProperties'] ) {
     1668            /* translators: 1: Parameter, 2: Number. */
     1669            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at least %2$s properties.' ), $param, number_format_i18n( $args['minProperties'] ) ) );
     1670        }
     1671
     1672        if ( isset( $args['maxProperties'] ) && count( $value ) > $args['maxProperties'] ) {
     1673            /* translators: 1: Parameter, 2: Number. */
     1674            return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at most %2$s properties.' ), $param, number_format_i18n( $args['maxProperties'] ) ) );
    16641675        }
    16651676    }
     
    22822293        'properties',
    22832294        'additionalProperties',
     2295        'minProperties',
     2296        'maxProperties',
    22842297        'minimum',
    22852298        'maximum',
Note: See TracChangeset for help on using the changeset viewer.