WP_REST_Global_Styles_Controller::get_theme_items()
Returns the given theme global styles variations.
Метод класса: WP_REST_Global_Styles_Controller{}
Хуков нет.
Возвращает
WP_REST_Response|WP_Error
.
Использование
$WP_REST_Global_Styles_Controller = new WP_REST_Global_Styles_Controller(); $WP_REST_Global_Styles_Controller->get_theme_items( $request );
- $request(WP_REST_Request) (обязательный)
- The request instance.
Список изменений
С версии 6.0.0 | Введена. |
С версии 6.2.0 | Returns parent theme variations, if they exist. |
С версии 6.6.0 | Added custom relative theme file URIs to _links for each item. |
Код WP_REST_Global_Styles_Controller::get_theme_items() WP REST Global Styles Controller::get theme items WP 6.6.2
public function get_theme_items( $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 ) ); } $response = array(); // Register theme-defined variations e.g. from block style variation partials under `/styles`. $partials = WP_Theme_JSON_Resolver::get_style_variations( 'block' ); wp_register_block_style_variations_from_theme_json_partials( $partials ); $variations = WP_Theme_JSON_Resolver::get_style_variations(); foreach ( $variations as $variation ) { $variation_theme_json = new WP_Theme_JSON( $variation ); $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $variation_theme_json ); $data = rest_ensure_response( $variation ); if ( ! empty( $resolved_theme_uris ) ) { $data->add_links( array( 'https://api.w.org/theme-file' => $resolved_theme_uris, ) ); } $response[] = $this->prepare_response_for_collection( $data ); } return rest_ensure_response( $response ); }