WP_REST_Themes_Controller::prepare_item_for_response( WP_Theme $theme, WP_REST_Request $request )

Prepares a single theme output for response.


Description Description


Parameters Parameters

$theme

(WP_Theme) (Required) Theme object.

$request

(WP_REST_Request) (Required) Request object.


Top ↑

Return Return

(WP_REST_Response) Response object.


Top ↑

Source Source

File: wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.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 ) ) {
			$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['theme_supports']['post-thumbnails']   = false;
			$data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' );
			$post_thumbnails                             = get_theme_support( 'post-thumbnails' );

			if ( $post_thumbnails ) {
				// $post_thumbnails can contain a nested array of post types.
				// e.g. array( array( 'post', 'page' ) ).
				$data['theme_supports']['post-thumbnails'] = is_array( $post_thumbnails ) ? $post_thumbnails[0] : true;
			}
		}

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

Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.