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.

Return

Mixed. Prepared value.

Usage

// 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.

Changelog

Since 4.7.0 Introduced.

WP_REST_Meta_Fields::prepare_value_for_response() code WP 6.6.2

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;
}