WP_REST_Settings_Controller::set_additional_properties_to_false

Advertisement

Summery Summery

Recursively add additionalProperties = false to all objects in a schema.

Syntax Syntax

WP_REST_Settings_Controller::set_additional_properties_to_false( array $schema )

Description Description

This is need to restrict properties of objects in settings values to only registered items, as the REST API will allow additional properties by default.

Parameters Parameters

$schema

(array) (Required) The schema array.

Return Return

(array)

Source Source

File: wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

	protected function set_additional_properties_to_false( $schema ) {
		switch ( $schema['type'] ) {
			case 'object':
				foreach ( $schema['properties'] as $key => $child_schema ) {
					$schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema );
				}

				$schema['additionalProperties'] = false;
				break;
			case 'array':
				$schema['items'] = $this->set_additional_properties_to_false( $schema['items'] );
				break;
		}

		return $schema;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
4.9.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.