Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ public function prepare_item_for_response( $item, $request ) {
$data['is_block_theme'] = $theme->is_block_theme();
}

if ( rest_is_field_included( 'has_theme_json', $fields ) ) {
$data['has_theme_json'] = wp_theme_has_theme_json();
}

if ( rest_is_field_included( 'stylesheet_uri', $fields ) ) {
if ( $this->is_same_theme( $theme, $current_theme ) ) {
$data['stylesheet_uri'] = get_stylesheet_directory_uri();
Expand Down Expand Up @@ -546,6 +550,11 @@ public function get_item_schema() {
'type' => 'boolean',
'readonly' => true,
),
'has_theme_json' => array(
'description' => __( 'Whether the theme has a theme.json file.' ),
'type' => 'boolean',
'readonly' => true,
),
'name' => array(
'description' => __( 'The name of the theme.' ),
'type' => 'object',
Expand Down
27 changes: 26 additions & 1 deletion tests/phpunit/tests/rest-api/rest-themes-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public function test_get_items() {
'default_template_types',
'description',
'is_block_theme',
'has_theme_json',
'name',
'requires_php',
'requires_wp',
Expand Down Expand Up @@ -222,6 +223,7 @@ public function test_get_items_inactive() {
'author_uri',
'description',
'is_block_theme',
'has_theme_json',
'name',
'requires_php',
'requires_wp',
Expand Down Expand Up @@ -363,7 +365,7 @@ public function test_get_item_schema() {
$response = self::perform_active_theme_request( 'OPTIONS' );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 20, $properties );
$this->assertCount( 21, $properties );

$this->assertArrayHasKey( 'author', $properties );
$this->assertArrayHasKey( 'raw', $properties['author']['properties'] );
Expand All @@ -381,6 +383,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'default_template_types', $properties );

$this->assertArrayHasKey( 'is_block_theme', $properties );
$this->assertArrayHasKey( 'has_theme_json', $properties );

$this->assertArrayHasKey( 'name', $properties );
$this->assertArrayHasKey( 'raw', $properties['name']['properties'] );
Expand Down Expand Up @@ -546,6 +549,27 @@ public function test_theme_is_block_theme() {
$this->assertTrue( $result[0]['is_block_theme'] );
}

/**
* @ticket 63253
* @covers WP_REST_Themes_Controller::prepare_item_for_response
*/
public function test_theme_has_theme_json() {
// Test classic theme (Theme without theme.json).
$response = self::perform_active_theme_request();
$result = $response->get_data();

$this->assertArrayHasKey( 'has_theme_json', $result[0] );
$this->assertFalse( $result[0]['has_theme_json'] );

// Test block theme (Theme with theme.json).
switch_theme( 'block-theme' );
$response = self::perform_active_theme_request();
$result = $response->get_data();

$this->assertArrayHasKey( 'has_theme_json', $result[0] );
$this->assertTrue( $result[0]['has_theme_json'] );
}

/**
* @ticket 49906
*/
Expand Down Expand Up @@ -1372,6 +1396,7 @@ public function test_get_item() {
'author_uri',
'description',
'is_block_theme',
'has_theme_json',
'name',
'requires_php',
'requires_wp',
Expand Down
Loading