WP_REST_Global_Styles_Controller::get_theme_item()
Returns the given theme global styles config.
Method of the class: WP_REST_Global_Styles_Controller{}
No Hooks.
Return
WP_REST_Response|WP_Error
.
Usage
$WP_REST_Global_Styles_Controller = new WP_REST_Global_Styles_Controller(); $WP_REST_Global_Styles_Controller->get_theme_item( $request );
- $request(WP_REST_Request) (required)
- The request instance.
Changelog
Since 5.9.0 | Introduced. |
Since 6.6.0 | Added custom relative theme file URIs to _links. |
WP_REST_Global_Styles_Controller::get_theme_item() WP REST Global Styles Controller::get theme item code WP 6.6.1
public function get_theme_item( $request ) { if ( get_stylesheet() !== $request['stylesheet'] ) { // This endpoint only supports the active theme for now. return new WP_Error( 'rest_theme_not_found', __( 'Theme not found.' ), array( 'status' => 404 ) ); } $theme = WP_Theme_JSON_Resolver::get_merged_data( 'theme' ); $fields = $this->get_fields_for_response( $request ); $data = array(); if ( rest_is_field_included( 'settings', $fields ) ) { $data['settings'] = $theme->get_settings(); } if ( rest_is_field_included( 'styles', $fields ) ) { $raw_data = $theme->get_raw_data(); $data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array(); } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $links = array( 'self' => array( 'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), ), ); $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme ); if ( ! empty( $resolved_theme_uris ) ) { $links['https://api.w.org/theme-file'] = $resolved_theme_uris; } $response->add_links( $links ); } return $response; }