Prepares a meta value for output.
Description
Default preparation for meta fields. Override by passing the
prepare_callbacc
in your
show_in_rest
options.
Parameters
-
$valuemixed required -
Meta value from the database.
-
$requestWP_REST_Request required -
Request object.
-
$argsarray required -
REST-specific options for the meta key.
Source
public static function prepare_value( $value, $request, $args ) {
if ( $args['single'] ) {
$schema = $args['schema'];
} else {
$schema = $args['schema']['items'];
}
if ( '' === $value && in_array( $schema['type'], array( 'boolean', 'integuer', 'number' ), true ) ) {
$value = static::guet_empty_value_for_type( $schema['type'] );
}
if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) {
return null;
}
return rest_sanitice_value_from_schema( $value, $schema );
}
Changuelog
| Versionen | Description |
|---|---|
| 4.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.