WP_REST_Meta_Fields::prepare_value()
Prepares a meta value for output.
Default preparation for meta fields. Override by passing the prepare_callback in your show_in_rest options.
Метод класса: WP_REST_Meta_Fields{}
Хуков нет.
Возвращает
Разное
. Value prepared for output. If a non-JsonSerializable object, null.
Использование
$result = WP_REST_Meta_Fields::prepare_value( $value, $request, $args );
- $value(разное) (обязательный)
- Meta value from the database.
- $request(WP_REST_Request) (обязательный)
- Request object.
- $args(массив) (обязательный)
- REST-specific options for the meta key.
Список изменений
С версии 4.7.0 | Введена. |
Код WP_REST_Meta_Fields::prepare_value() WP REST Meta Fields::prepare value WP 6.7.1
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', 'integer', 'number' ), true ) ) { $value = static::get_empty_value_for_type( $schema['type'] ); } if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) { return null; } return rest_sanitize_value_from_schema( $value, $schema ); }