WP_REST_Meta_Fields::prepare_value_for_response()protectedWP 4.7.0

Prepares a meta value for a response.

This is required because some native types cannot be stored correctly in the database, such as booleans. We need to cast back to the relevant type before passing back to JSON.

Method of the class: WP_REST_Meta_Fields{}

No Hooks.


Mixed. Prepared value.


// protected - for code of main (parent) or child class
$result = $this->prepare_value_for_response( $value, $request, $args );
$value(mixed) (required)
Meta value to prepare.
$request(WP_REST_Request) (required)
Current request object.
$args(array) (required)
Options for the field.


Since 4.7.0 Introduced.

WP_REST_Meta_Fields::prepare_value_for_response() code WP 6.4.1

protected function prepare_value_for_response( $value, $request, $args ) {
	if ( ! empty( $args['prepare_callback'] ) ) {
		$value = call_user_func( $args['prepare_callback'], $value, $request, $args );

	return $value;