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.
Return Return
(WP_REST_Response) Response object.
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 ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |