mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-21 03:34:28 +00:00
REST API: Indicate when a theme supports the Site editor in the Themes REST API response.
This changeset adds a `is_block_theme` property to each theme in the `wp/v2/themes` API response, which uses `WP_Theme::is_block_theme` to determinate whether the theme is block theme or not. Props grantmkin, ironprogrammer, zunaid321, azaozz, spacedmonkey, audrasjb, costdev. Fixes #58123. git-svn-id: https://develop.svn.wordpress.org/trunk@55951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -326,6 +326,10 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'is_block_theme', $fields ) ) {
|
||||
$data['is_block_theme'] = $theme->is_block_theme();
|
||||
}
|
||||
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
@@ -494,6 +498,11 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
||||
),
|
||||
),
|
||||
),
|
||||
'is_block_theme' => array(
|
||||
'description' => __( 'Whether the theme is a block-based theme.' ),
|
||||
'type' => 'boolean',
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'The name of the theme.' ),
|
||||
'type' => 'object',
|
||||
|
||||
@@ -172,6 +172,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'author',
|
||||
'author_uri',
|
||||
'description',
|
||||
'is_block_theme',
|
||||
'name',
|
||||
'requires_php',
|
||||
'requires_wp',
|
||||
@@ -185,6 +186,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'theme_uri',
|
||||
'version',
|
||||
);
|
||||
$this->assertIsArray( $data );
|
||||
$this->assertNotEmpty( $data );
|
||||
$this->assertSameSets( $fields, array_keys( $data[0] ) );
|
||||
}
|
||||
|
||||
@@ -208,6 +211,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'author',
|
||||
'author_uri',
|
||||
'description',
|
||||
'is_block_theme',
|
||||
'name',
|
||||
'requires_php',
|
||||
'requires_wp',
|
||||
@@ -220,6 +224,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'theme_uri',
|
||||
'version',
|
||||
);
|
||||
$this->assertIsArray( $data );
|
||||
$this->assertNotEmpty( $data );
|
||||
$this->assertSameSets( $fields, array_keys( $data[0] ) );
|
||||
|
||||
$this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) );
|
||||
@@ -343,7 +349,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$response = self::perform_active_theme_request( 'OPTIONS' );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertCount( 15, $properties );
|
||||
$this->assertCount( 16, $properties );
|
||||
|
||||
$this->assertArrayHasKey( 'author', $properties );
|
||||
$this->assertArrayHasKey( 'raw', $properties['author']['properties'] );
|
||||
@@ -357,6 +363,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertArrayHasKey( 'raw', $properties['description']['properties'] );
|
||||
$this->assertArrayHasKey( 'rendered', $properties['description']['properties'] );
|
||||
|
||||
$this->assertArrayHasKey( 'is_block_theme', $properties );
|
||||
|
||||
$this->assertArrayHasKey( 'name', $properties );
|
||||
$this->assertArrayHasKey( 'raw', $properties['name']['properties'] );
|
||||
$this->assertArrayHasKey( 'rendered', $properties['name']['properties'] );
|
||||
@@ -471,6 +479,27 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertSame( '5.3', $result[0]['requires_wp'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58123
|
||||
* @covers WP_REST_Themes_Controller::prepare_item_for_response
|
||||
*/
|
||||
public function test_theme_is_block_theme() {
|
||||
// Test classic theme, activated in test setup.
|
||||
$response = self::perform_active_theme_request();
|
||||
$result = $response->get_data();
|
||||
|
||||
$this->assertArrayHasKey( 'is_block_theme', $result[0] );
|
||||
$this->assertFalse( $result[0]['is_block_theme'] );
|
||||
|
||||
// Test block theme.
|
||||
switch_theme( 'block-theme' );
|
||||
$response = self::perform_active_theme_request();
|
||||
$result = $response->get_data();
|
||||
|
||||
$this->assertArrayHasKey( 'is_block_theme', $result[0] );
|
||||
$this->assertTrue( $result[0]['is_block_theme'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 49906
|
||||
*/
|
||||
@@ -1234,6 +1263,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'author',
|
||||
'author_uri',
|
||||
'description',
|
||||
'is_block_theme',
|
||||
'name',
|
||||
'requires_php',
|
||||
'requires_wp',
|
||||
|
||||
Reference in New Issue
Block a user