Prepares a value for output based off a schema array.
Parameters
$value
mixedrequired- Value to prepare.
$schema
arrayrequired- Schema to match.
Source
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 );
}
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.