Make WordPress Core


Ignore:
Timestamp:
09/11/2022 11:28:39 PM (21 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add support for settings to specify their own additionalProperties.

This switches the Settings Controller to use rest_default_additional_properties_to_false and deprecates its own method.

Props anna.bansaghi.
Fixes #56493.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

    r51000 r54131  
    259259            }
    260260
    261             $rest_args['schema'] = $this->set_additional_properties_to_false( $rest_args['schema'] );
     261            $rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] );
    262262
    263263            $rest_options[ $rest_args['name'] ] = $rest_args;
     
    323323
    324324    /**
    325      * Recursively add additionalProperties = false to all objects in a schema.
    326      *
    327      * This is need to restrict properties of objects in settings values to only
     325     * Recursively add additionalProperties = false to all objects in a schema
     326     * if no additionalProperties setting is specified.
     327     *
     328     * This is needed to restrict properties of objects in settings values to only
    328329     * registered items, as the REST API will allow additional properties by
    329330     * default.
    330331     *
    331332     * @since 4.9.0
     333     * @deprecated 6.1.0 Use {@see rest_default_additional_properties_to_false()} instead.
    332334     *
    333335     * @param array $schema The schema array.
     
    335337     */
    336338    protected function set_additional_properties_to_false( $schema ) {
    337         switch ( $schema['type'] ) {
    338             case 'object':
    339                 foreach ( $schema['properties'] as $key => $child_schema ) {
    340                     $schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema );
    341                 }
    342 
    343                 $schema['additionalProperties'] = false;
    344                 break;
    345             case 'array':
    346                 $schema['items'] = $this->set_additional_properties_to_false( $schema['items'] );
    347                 break;
    348         }
    349 
    350         return $schema;
     339        _deprecated_function( __METHOD__, '6.1.0', 'rest_default_additional_properties_to_false()' );
     340
     341        return rest_default_additional_properties_to_false( $schema );
    351342    }
    352343}
Note: See TracChangeset for help on using the changeset viewer.