mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-22 23:41:38 +01:00
REST API: Prevent PHP warning when metadata schema is missing properties.
This switches to the new `rest_default_additional_properties_to_false()` function which doesn't have this issue and deprecates the `WP_REST_Meta_Fields::default_additional_properties_to_false()` method. Props austin880625. Fixes #51389. Built from https://develop.svn.wordpress.org/trunk@49308 git-svn-id: http://core.svn.wordpress.org/trunk@49070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f5457dff2
commit
367c97df67
@ -466,7 +466,7 @@ abstract class WP_REST_Meta_Fields {
|
|||||||
$rest_args['schema']['default'] = static::get_empty_value_for_type( $type );
|
$rest_args['schema']['default'] = static::get_empty_value_for_type( $type );
|
||||||
}
|
}
|
||||||
|
|
||||||
$rest_args['schema'] = $this->default_additional_properties_to_false( $rest_args['schema'] );
|
$rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] );
|
||||||
|
|
||||||
if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
|
if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
|
||||||
continue;
|
continue;
|
||||||
@ -571,27 +571,15 @@ abstract class WP_REST_Meta_Fields {
|
|||||||
* default.
|
* default.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.0
|
||||||
|
* @deprecated 5.6.0 Use 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 default_additional_properties_to_false( $schema ) {
|
protected function default_additional_properties_to_false( $schema ) {
|
||||||
switch ( $schema['type'] ) {
|
_deprecated_function( __METHOD__, '5.6.0', 'rest_default_additional_properties_to_false()' );
|
||||||
case 'object':
|
|
||||||
foreach ( $schema['properties'] as $key => $child_schema ) {
|
|
||||||
$schema['properties'][ $key ] = $this->default_additional_properties_to_false( $child_schema );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! isset( $schema['additionalProperties'] ) ) {
|
return rest_default_additional_properties_to_false( $schema );
|
||||||
$schema['additionalProperties'] = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'array':
|
|
||||||
$schema['items'] = $this->default_additional_properties_to_false( $schema['items'] );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.6-beta1-49306';
|
$wp_version = '5.6-beta1-49308';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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…
Reference in New Issue
Block a user