wp/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    52 					'permission_callback' => array( $this, 'get_item_permissions_check' ),
    52 					'permission_callback' => array( $this, 'get_item_permissions_check' ),
    53 				),
    53 				),
    54 				'schema' => array( $this, 'get_public_item_schema' ),
    54 				'schema' => array( $this, 'get_public_item_schema' ),
    55 			)
    55 			)
    56 		);
    56 		);
    57 
       
    58 	}
    57 	}
    59 
    58 
    60 	/**
    59 	/**
    61 	 * Checks if a given request has access to read and manage settings.
    60 	 * Checks if a given request has access to read and manage settings.
    62 	 *
    61 	 *
   236 
   235 
   237 			$rest_args = array_merge( $defaults, $rest_args );
   236 			$rest_args = array_merge( $defaults, $rest_args );
   238 
   237 
   239 			$default_schema = array(
   238 			$default_schema = array(
   240 				'type'        => empty( $args['type'] ) ? null : $args['type'],
   239 				'type'        => empty( $args['type'] ) ? null : $args['type'],
       
   240 				'title'       => empty( $args['label'] ) ? '' : $args['label'],
   241 				'description' => empty( $args['description'] ) ? '' : $args['description'],
   241 				'description' => empty( $args['description'] ) ? '' : $args['description'],
   242 				'default'     => isset( $args['default'] ) ? $args['default'] : null,
   242 				'default'     => isset( $args['default'] ) ? $args['default'] : null,
   243 			);
   243 			);
   244 
   244 
   245 			$rest_args['schema']      = array_merge( $default_schema, $rest_args['schema'] );
   245 			$rest_args['schema']      = array_merge( $default_schema, $rest_args['schema'] );
   256 			 */
   256 			 */
   257 			if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean', 'array', 'object' ), true ) ) {
   257 			if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean', 'array', 'object' ), true ) ) {
   258 				continue;
   258 				continue;
   259 			}
   259 			}
   260 
   260 
   261 			$rest_args['schema'] = $this->set_additional_properties_to_false( $rest_args['schema'] );
   261 			$rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] );
   262 
   262 
   263 			$rest_options[ $rest_args['name'] ] = $rest_args;
   263 			$rest_options[ $rest_args['name'] ] = $rest_args;
   264 		}
   264 		}
   265 
   265 
   266 		return $rest_options;
   266 		return $rest_options;
   320 
   320 
   321 		return rest_parse_request_arg( $value, $request, $param );
   321 		return rest_parse_request_arg( $value, $request, $param );
   322 	}
   322 	}
   323 
   323 
   324 	/**
   324 	/**
   325 	 * Recursively add additionalProperties = false to all objects in a schema.
   325 	 * Recursively add additionalProperties = false to all objects in a schema
   326 	 *
   326 	 * if no additionalProperties setting is specified.
   327 	 * This is need to restrict properties of objects in settings values to only
   327 	 *
       
   328 	 * This is needed to restrict properties of objects in settings values to only
   328 	 * registered items, as the REST API will allow additional properties by
   329 	 * registered items, as the REST API will allow additional properties by
   329 	 * default.
   330 	 * default.
   330 	 *
   331 	 *
   331 	 * @since 4.9.0
   332 	 * @since 4.9.0
       
   333 	 * @deprecated 6.1.0 Use {@see rest_default_additional_properties_to_false()} instead.
   332 	 *
   334 	 *
   333 	 * @param array $schema The schema array.
   335 	 * @param array $schema The schema array.
   334 	 * @return array
   336 	 * @return array
   335 	 */
   337 	 */
   336 	protected function set_additional_properties_to_false( $schema ) {
   338 	protected function set_additional_properties_to_false( $schema ) {
   337 		switch ( $schema['type'] ) {
   339 		_deprecated_function( __METHOD__, '6.1.0', 'rest_default_additional_properties_to_false()' );
   338 			case 'object':
   340 
   339 				foreach ( $schema['properties'] as $key => $child_schema ) {
   341 		return rest_default_additional_properties_to_false( $schema );
   340 					$schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema );
       
   341 				}
       
   342 
       
   343 				$schema['additionalProperties'] = false;
       
   344 				break;
       
   345 			case 'array':
       
   346 				$schema['items'] = $this->set_additional_properties_to_false( $schema['items'] );
       
   347 				break;
       
   348 		}
       
   349 
       
   350 		return $schema;
       
   351 	}
   342 	}
   352 }
   343 }