From 3646dd2e9f8c80d924a6b6a691a5c1387e51c2c4 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 25 Oct 2020 20:28:50 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@49308 602fd350-edb4-49c9-b593-d223f7449a82 --- .../fields/class-wp-rest-meta-fields.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php index f7a47483a4..199c54f8f1 100644 --- a/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php +++ b/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php @@ -466,7 +466,7 @@ abstract class WP_REST_Meta_Fields { $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 ) ) { continue; @@ -571,27 +571,15 @@ abstract class WP_REST_Meta_Fields { * default. * * @since 5.3.0 + * @deprecated 5.6.0 Use rest_default_additional_properties_to_false() instead. * * @param array $schema The schema array. * @return array */ protected function default_additional_properties_to_false( $schema ) { - switch ( $schema['type'] ) { - case 'object': - foreach ( $schema['properties'] as $key => $child_schema ) { - $schema['properties'][ $key ] = $this->default_additional_properties_to_false( $child_schema ); - } + _deprecated_function( __METHOD__, '5.6.0', 'rest_default_additional_properties_to_false()' ); - if ( ! isset( $schema['additionalProperties'] ) ) { - $schema['additionalProperties'] = false; - } - break; - case 'array': - $schema['items'] = $this->default_additional_properties_to_false( $schema['items'] ); - break; - } - - return $schema; + return rest_default_additional_properties_to_false( $schema ); } /**