On this page
WP_REST_Settings_Controller::prepare_value( mixed $value, array $schema ): mixed
Prepares a value for output based off a schema array.
Parameters
$valuemixed Required-
Value to prepare.
$schemaarray Required-
Schema to match.
Return
mixed The prepared value.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| rest_sanitize_value_from_schema() wp-includes/rest-api.php | Sanitize a value based on a schema. |
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Settings_Controller::get_item() wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves the settings. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_settings_controller/prepare_value