WP_REST_Global_Styles_Controller::get_theme_item() WordPress Method
The WP_REST_Global_Styles_Controller::get_theme_item() method is used to retrieve a specific global style. This method accepts two parameters: the global style ID and the theme ID. The global style ID is used to identify the global style while the theme ID is used to identify the theme.
WP_REST_Global_Styles_Controller::get_theme_item( WP_REST_Request $request ) #
Returns the given theme global styles config.
Parameters
- $request
(WP_REST_Request)(Required)The request instance.
Return
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
public function get_theme_item( $request ) {
if ( wp_get_theme()->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' );
$data = array();
$fields = $this->get_fields_for_response( $request );
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 );
$links = array(
'self' => array(
'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ),
),
);
$response->add_links( $links );
return $response;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |