Make WordPress Core

Changeset 49308


Ignore:
Timestamp:
10/25/2020 08:28:50 PM (5 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    r49295 r49308  
    467467            }
    468468
    469             $rest_args['schema'] = $this->default_additional_properties_to_false( $rest_args['schema'] );
     469            $rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] );
    470470
    471471            if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
     
    572572     *
    573573     * @since 5.3.0
     574     * @deprecated 5.6.0 Use rest_default_additional_properties_to_false() instead.
    574575     *
    575576     * @param array $schema The schema array.
     
    577578     */
    578579    protected function default_additional_properties_to_false( $schema ) {
    579         switch ( $schema['type'] ) {
    580             case 'object':
    581                 foreach ( $schema['properties'] as $key => $child_schema ) {
    582                     $schema['properties'][ $key ] = $this->default_additional_properties_to_false( $child_schema );
    583                 }
    584 
    585                 if ( ! isset( $schema['additionalProperties'] ) ) {
    586                     $schema['additionalProperties'] = false;
    587                 }
    588                 break;
    589             case 'array':
    590                 $schema['items'] = $this->default_additional_properties_to_false( $schema['items'] );
    591                 break;
    592         }
    593 
    594         return $schema;
     580        _deprecated_function( __METHOD__, '5.6.0', 'rest_default_additional_properties_to_false()' );
     581
     582        return rest_default_additional_properties_to_false( $schema );
    595583    }
    596584
Note: See TracChangeset for help on using the changeset viewer.