mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-18 04:25:07 +00:00
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. Built from https://develop.svn.wordpress.org/trunk@54131 git-svn-id: http://core.svn.wordpress.org/trunk@53690 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f185aeb638
commit
950bf585bc
@ -258,7 +258,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rest_args['schema'] = $this->set_additional_properties_to_false( $rest_args['schema'] );
|
$rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] );
|
||||||
|
|
||||||
$rest_options[ $rest_args['name'] ] = $rest_args;
|
$rest_options[ $rest_args['name'] ] = $rest_args;
|
||||||
}
|
}
|
||||||
@ -322,31 +322,22 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively add additionalProperties = false to all objects in a schema.
|
* Recursively add additionalProperties = false to all objects in a schema
|
||||||
|
* if no additionalProperties setting is specified.
|
||||||
*
|
*
|
||||||
* This is need to restrict properties of objects in settings values to only
|
* This is needed to restrict properties of objects in settings values to only
|
||||||
* registered items, as the REST API will allow additional properties by
|
* registered items, as the REST API will allow additional properties by
|
||||||
* default.
|
* default.
|
||||||
*
|
*
|
||||||
* @since 4.9.0
|
* @since 4.9.0
|
||||||
|
* @deprecated 6.1.0 Use {@see rest_default_additional_properties_to_false()} instead.
|
||||||
*
|
*
|
||||||
* @param array $schema The schema array.
|
* @param array $schema The schema array.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function set_additional_properties_to_false( $schema ) {
|
protected function set_additional_properties_to_false( $schema ) {
|
||||||
switch ( $schema['type'] ) {
|
_deprecated_function( __METHOD__, '6.1.0', 'rest_default_additional_properties_to_false()' );
|
||||||
case 'object':
|
|
||||||
foreach ( $schema['properties'] as $key => $child_schema ) {
|
|
||||||
$schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema );
|
|
||||||
}
|
|
||||||
|
|
||||||
$schema['additionalProperties'] = false;
|
return rest_default_additional_properties_to_false( $schema );
|
||||||
break;
|
|
||||||
case 'array':
|
|
||||||
$schema['items'] = $this->set_additional_properties_to_false( $schema['items'] );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-alpha-54130';
|
$wp_version = '6.1-alpha-54131';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user