Skip to content

Commit ef303f5

Browse files
committed
update styles controller to fetch gutenberg bundled theme.json
1 parent 78c25cf commit ef303f5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lib/compat/wordpress-6.2/class-gutenberg-rest-global-styles-controller-6-2.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,55 @@ private function validate_custom_css( $css ) {
201201
}
202202
return true;
203203
}
204+
205+
/**
206+
* Returns the given theme global styles config.
207+
* Duplicated from core.
208+
* The only change is that we call WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( 'theme' ) instead of WP_Theme_JSON_Resolver::get_merged_data( 'theme' ).
209+
*
210+
* @since 6.2.0
211+
*
212+
* @param WP_REST_Request $request The request instance.
213+
* @return WP_REST_Response|WP_Error
214+
*/
215+
public function get_theme_item( $request ) {
216+
if ( get_stylesheet() !== $request['stylesheet'] ) {
217+
// This endpoint only supports the active theme for now.
218+
return new WP_Error(
219+
'rest_theme_not_found',
220+
__( 'Theme not found.', 'gutenberg' ),
221+
array( 'status' => 404 )
222+
);
223+
}
224+
225+
$theme = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( 'theme' );
226+
$data = array();
227+
$fields = $this->get_fields_for_response( $request );
228+
229+
if ( rest_is_field_included( 'settings', $fields ) ) {
230+
$data['settings'] = $theme->get_settings();
231+
}
232+
233+
if ( rest_is_field_included( 'styles', $fields ) ) {
234+
$raw_data = $theme->get_raw_data();
235+
$data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
236+
}
237+
238+
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
239+
$data = $this->add_additional_fields_to_object( $data, $request );
240+
$data = $this->filter_response_by_context( $data, $context );
241+
242+
$response = rest_ensure_response( $data );
243+
244+
if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
245+
$links = array(
246+
'self' => array(
247+
'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ),
248+
),
249+
);
250+
$response->add_links( $links );
251+
}
252+
253+
return $response;
254+
}
204255
}

0 commit comments

Comments
 (0)