Changeset 58262 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
- Timestamp:
- 05/31/2024 01:17:50 AM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
r58225 r58262 290 290 * 291 291 * @since 5.9.0 292 * @since 6.6.0 Added custom relative theme file URIs to `_links`. 292 293 * 293 294 * @param WP_Post $post Global Styles post object. … … 299 300 $is_global_styles_user_theme_json = isset( $raw_config['isGlobalStylesUserThemeJSON'] ) && true === $raw_config['isGlobalStylesUserThemeJSON']; 300 301 $config = array(); 302 $theme_json = null; 301 303 if ( $is_global_styles_user_theme_json ) { 302 $config = ( new WP_Theme_JSON( $raw_config, 'custom' ) )->get_raw_data(); 304 $theme_json = new WP_Theme_JSON( $raw_config, 'custom' ); 305 $config = $theme_json->get_raw_data(); 303 306 } 304 307 … … 342 345 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 343 346 $links = $this->prepare_links( $post->ID ); 347 348 // Only return resolved URIs for get requests to user theme JSON. 349 if ( $theme_json ) { 350 $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme_json ); 351 if ( ! empty( $resolved_theme_uris ) ) { 352 $links['https://api.w.org/theme-file'] = $resolved_theme_uris; 353 } 354 } 355 344 356 $response->add_links( $links ); 345 357 if ( ! empty( $links['self']['href'] ) ) { … … 516 528 * 517 529 * @since 5.9.0 530 * @since 6.6.0 Added custom relative theme file URIs to `_links`. 518 531 * 519 532 * @param WP_REST_Request $request The request instance. … … 550 563 551 564 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 552 $links = array(565 $links = array( 553 566 'self' => array( 554 567 'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), 555 568 ), 556 569 ); 570 $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme ); 571 if ( ! empty( $resolved_theme_uris ) ) { 572 $links['https://api.w.org/theme-file'] = $resolved_theme_uris; 573 } 557 574 $response->add_links( $links ); 558 575 } … … 592 609 * @since 6.0.0 593 610 * @since 6.2.0 Returns parent theme variations, if they exist. 611 * @since 6.6.0 Added custom relative theme file URIs to `_links` for each item. 594 612 * 595 613 * @param WP_REST_Request $request The request instance. … … 607 625 } 608 626 627 $response = array(); 609 628 $variations = WP_Theme_JSON_Resolver::get_style_variations(); 610 629 611 return rest_ensure_response( $variations ); 630 foreach ( $variations as $variation ) { 631 $variation_theme_json = new WP_Theme_JSON( $variation ); 632 $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $variation_theme_json ); 633 $data = rest_ensure_response( $variation ); 634 if ( ! empty( $resolved_theme_uris ) ) { 635 $data->add_links( 636 array( 637 'https://api.w.org/theme-file' => $resolved_theme_uris, 638 ) 639 ); 640 } 641 $response[] = $this->prepare_response_for_collection( $data ); 642 } 643 644 return rest_ensure_response( $response ); 612 645 } 613 646
Note: See TracChangeset
for help on using the changeset viewer.