- Timestamp:
- 10/24/2017 09:04:50 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
r41758 r42000 249 249 } 250 250 251 $rest_args['schema'] = $this->set_additional_properties_to_false( $rest_args['schema'] ); 252 251 253 $rest_options[ $rest_args['name'] ] = $rest_args; 252 254 } … … 302 304 return rest_parse_request_arg( $value, $request, $param ); 303 305 } 306 307 /** 308 * Recursively add additionalProperties = false to all objects in a schema. 309 * 310 * This is need to restrict properties of objects in settings values to only 311 * registered items, as the REST API will allow additional properties by 312 * default. 313 * 314 * @since 4.9.0 315 * 316 * @param array $schema The schema array. 317 * @return array 318 */ 319 protected function set_additional_properties_to_false( $schema ) { 320 switch ( $schema['type'] ) { 321 case 'object': 322 foreach ( $schema['properties'] as $key => $child_schema ) { 323 $schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema ); 324 } 325 $schema['additionalProperties'] = false; 326 break; 327 case 'array': 328 $schema['items'] = $this->set_additional_properties_to_false( $schema['items'] ); 329 break; 330 } 331 332 return $schema; 333 } 304 334 }
Note: See TracChangeset
for help on using the changeset viewer.