WordPress at a glance
function is not described

WP_REST_Themes_Controller::prepare_item_for_response() WP 5.0.0

Prepares a single theme output for response.

This is a method of the class: WP_REST_Themes_Controller

Hooks from the method
Return

WP_REST_Response. Response object.

Usage

$WP_REST_Themes_Controller = new WP_REST_Themes_Controller();
$var = $WP_REST_Themes_Controller->prepare_item_for_response( $theme, $request );
$theme(WP_Theme) (required)
Theme object.
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 5.0.0 Introduced.

Code of WP REST Themes Controller::prepare item for response: wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php WP 5.4.1

<?php
public function prepare_item_for_response( $theme, $request ) {
	$data   = array();
	$fields = $this->get_fields_for_response( $request );

	if ( in_array( 'theme_supports', $fields, true ) ) {
		$item_schemas   = $this->get_item_schema();
		$theme_supports = $item_schemas['properties']['theme_supports']['properties'];
		foreach ( $theme_supports as $name => $schema ) {
			if ( 'formats' === $name ) {
				continue;
			}

			if ( ! current_theme_supports( $name ) ) {
				$data['theme_supports'][ $name ] = false;
				continue;
			}

			if ( 'boolean' === $schema['type'] ) {
				$data['theme_supports'][ $name ] = true;
				continue;
			}

			$support = get_theme_support( $name );

			if ( is_array( $support ) ) {
				// None of the Core theme supports have variadic args.
				$support = $support[0];

				// Core multi-type theme-support schema definitions always list boolean first.
				if ( is_array( $schema['type'] ) && 'boolean' === $schema['type'][0] ) {
					// Pass the non-boolean type through to the sanitizer, which cannot itself
					// determine the intended type if the value is invalid (for example if an
					// object includes non-safelisted properties).
					$schema['type'] = $schema['type'][1];
				}
			}

			$data['theme_supports'][ $name ] = rest_sanitize_value_from_schema( $support, $schema );
		}

		$formats = get_theme_support( 'post-formats' );
		$formats = is_array( $formats ) ? array_values( $formats[0] ) : array();
		$formats = array_merge( array( 'standard' ), $formats );

		$data['theme_supports']['formats'] = $formats;
	}

	$data = $this->add_additional_fields_to_object( $data, $request );

	// Wrap the data in a response object.
	$response = rest_ensure_response( $data );

	/**
	 * Filters theme data returned from the REST API.
	 *
	 * @since 5.0.0
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param WP_Theme         $theme    Theme object used to create response.
	 * @param WP_REST_Request  $request  Request object.
	 */
	return apply_filters( 'rest_prepare_theme', $response, $theme, $request );
}