From 53e041b361c64e41a63fdcc454c4473219d384b5 Mon Sep 17 00:00:00 2001 From: TimothyBlynJacobs Date: Sun, 2 Jun 2024 19:27:15 +0000 Subject: [PATCH] REST API: Add stylesheet and template URI fields to the Themes API. Props andrewserong, timothyblynjacobs, noisysocks, ramonopoly, peterwilsoncc, Dharm1025. Fixes #61021. Built from https://develop.svn.wordpress.org/trunk@58282 git-svn-id: http://core.svn.wordpress.org/trunk@57742 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-themes-controller.php | 29 +++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 064fc2dd39..0f4da6773a 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -224,6 +224,7 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { * * @since 5.0.0 * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support. + * @since 6.6.0 Added `stylesheet_uri` and `template_uri` fields. * * @param WP_Theme $item Theme object. * @param WP_REST_Request $request Request object. @@ -331,6 +332,22 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { $data['is_block_theme'] = $theme->is_block_theme(); } + if ( rest_is_field_included( 'stylesheet_uri', $fields ) ) { + if ( $this->is_same_theme( $theme, $current_theme ) ) { + $data['stylesheet_uri'] = get_stylesheet_directory_uri(); + } else { + $data['stylesheet_uri'] = $theme->get_stylesheet_directory_uri(); + } + } + + if ( rest_is_field_included( 'template_uri', $fields ) ) { + if ( $this->is_same_theme( $theme, $current_theme ) ) { + $data['template_uri'] = get_template_directory_uri(); + } else { + $data['template_uri'] = $theme->get_template_directory_uri(); + } + } + $data = $this->add_additional_fields_to_object( $data, $request ); // Wrap the data in a response object. @@ -447,11 +464,23 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { 'type' => 'string', 'readonly' => true, ), + 'stylesheet_uri' => array( + 'description' => __( 'The uri for the theme\'s stylesheet directory.' ), + 'type' => 'string', + 'format' => 'uri', + 'readonly' => true, + ), 'template' => array( 'description' => __( 'The theme\'s template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet.' ), 'type' => 'string', 'readonly' => true, ), + 'template_uri' => array( + 'description' => __( 'The uri for the theme\'s template directory. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet directory.' ), + 'type' => 'string', + 'format' => 'uri', + 'readonly' => true, + ), 'author' => array( 'description' => __( 'The theme author.' ), 'type' => 'object', diff --git a/wp-includes/version.php b/wp-includes/version.php index b7795d0726..b3b0bd66d0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58281'; +$wp_version = '6.6-alpha-58282'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.