WP_REST_Settings_Controller::prepare_value() WordPress Method

The WP_REST_Settings_Controller::prepare_value() method is used to prepare a setting value for output in the REST API. This is a helper method that should be called by the `prepare_item()` method of a controller for a setting.

WP_REST_Settings_Controller::prepare_value( mixed $value, array $schema ) #

Prepares a value for output based off a schema array.


Parameters

$value

(mixed)(Required)Value to prepare.

$schema

(array)(Required)Schema to match.


Top ↑

Return

(mixed) The prepared value.


Top ↑

Source

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

	protected function prepare_value( $value, $schema ) {
		/*
		 * If the value is not valid by the schema, set the value to null.
		 * Null values are specifically non-destructive, so this will not cause
		 * overwriting the current invalid value to null.
		 */
		if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) {
			return null;
		}

		return rest_sanitize_value_from_schema( $value, $schema );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.