diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
index 47491e7774..1eb7d468d7 100644
|
a
|
b
|
class WP_REST_Themes_Controller extends WP_REST_Controller {
|
| 111 | 111 | $formats = array_merge( array( 'standard' ), $formats ); |
| 112 | 112 | $data['theme_supports']['formats'] = $formats; |
| 113 | 113 | |
| 114 | | $data['theme_supports']['post-thumbnails'] = false; |
| 115 | | $data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' ); |
| 116 | | $post_thumbnails = get_theme_support( 'post-thumbnails' ); |
| | 114 | $data['theme_supports']['post-thumbnails'] = false; |
| | 115 | $data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' ); |
| | 116 | $data['theme_supports']['editor-color-palette'] = false; |
| | 117 | $post_thumbnails = get_theme_support( 'post-thumbnails' ); |
| | 118 | $editor_color_palette = get_theme_support( 'editor-color-palette' ); |
| 117 | 119 | |
| 118 | 120 | if ( $post_thumbnails ) { |
| 119 | 121 | // $post_thumbnails can contain a nested array of post types. |
| 120 | 122 | // e.g. array( array( 'post', 'page' ) ). |
| 121 | 123 | $data['theme_supports']['post-thumbnails'] = is_array( $post_thumbnails ) ? $post_thumbnails[0] : true; |
| 122 | 124 | } |
| | 125 | |
| | 126 | if ( is_array( $editor_color_palette ) ) { |
| | 127 | $data['theme_supports']['editor-color-palette'] = $editor_color_palette[0]; |
| | 128 | } |
| 123 | 129 | } |
| 124 | 130 | |
| 125 | 131 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| … |
… |
class WP_REST_Themes_Controller extends WP_REST_Controller {
|
| 176 | 182 | 'type' => 'bool', |
| 177 | 183 | 'readonly' => true, |
| 178 | 184 | ), |
| | 185 | 'editor-color-palette' => array( |
| | 186 | 'description' => __( 'Whether the theme supports a custom color scheme.' ), |
| | 187 | 'type' => array( 'array', 'bool' ), |
| | 188 | 'items' => [ |
| | 189 | 'type' => 'object', |
| | 190 | 'properties' => array( |
| | 191 | 'name' => 'string', |
| | 192 | 'slug' => 'string', |
| | 193 | 'color' => 'string,' |
| | 194 | ), |
| | 195 | 'required' => [ 'name', 'slug', 'color' ], |
| | 196 | ], |
| | 197 | 'readonly' => true, |
| | 198 | ), |
| 179 | 199 | ), |
| 180 | 200 | ), |
| 181 | 201 | ), |
diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php
index 520dbed9d0..eca8178e3c 100644
|
a
|
b
|
class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
| 189 | 189 | $this->assertEquals( 1, count( $properties ) ); |
| 190 | 190 | $this->assertArrayHasKey( 'theme_supports', $properties ); |
| 191 | 191 | |
| 192 | | $this->assertEquals( 3, count( $properties['theme_supports']['properties'] ) ); |
| | 192 | $this->assertEquals( 4, count( $properties['theme_supports']['properties'] ) ); |
| 193 | 193 | $this->assertArrayHasKey( 'formats', $properties['theme_supports']['properties'] ); |
| 194 | 194 | $this->assertArrayHasKey( 'post-thumbnails', $properties['theme_supports']['properties'] ); |
| 195 | 195 | $this->assertArrayHasKey( 'responsive-embeds', $properties['theme_supports']['properties'] ); |
| | 196 | $this->assertArrayHasKey( 'editor-color-palette', $properties['theme_supports']['properties'] ); |
| 196 | 197 | } |
| 197 | 198 | |
| 198 | 199 | /** |
| … |
… |
class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
| 295 | 296 | $this->assertEquals( array( 'post' ), $result[0]['theme_supports']['post-thumbnails'] ); |
| 296 | 297 | } |
| 297 | 298 | |
| | 299 | /** |
| | 300 | * Test when a theme doesn't support a custom color palette. |
| | 301 | * |
| | 302 | * @ticket TBD |
| | 303 | */ |
| | 304 | public function test_theme_supports_editor_color_palette_false() { |
| | 305 | remove_theme_support( 'editor-color-palette' ); |
| | 306 | $response = self::perform_active_theme_request(); |
| | 307 | |
| | 308 | $result = $response->get_data(); |
| | 309 | $this->assertTrue( isset( $result[0]['theme_supports'] ) ); |
| | 310 | $this->assertTrue( isset( $result[0]['theme_supports']['editor-color-palette'] ) ); |
| | 311 | $this->assertFalse( $result[0]['theme_supports']['editor-color-palette'] ); |
| | 312 | } |
| | 313 | |
| | 314 | /** |
| | 315 | * Test when a theme doesn't support a custom color palette. |
| | 316 | * |
| | 317 | * @ticket TBD |
| | 318 | */ |
| | 319 | public function test_theme_supports_editor_color_palette_array() { |
| | 320 | remove_theme_support( 'editor-color-palette' ); |
| | 321 | $wordpress_blue = array( |
| | 322 | 'name' => 'WordPress Blue', |
| | 323 | 'slug' => 'wordpress-blue', |
| | 324 | 'color' => '#0073AA', |
| | 325 | ); |
| | 326 | add_theme_support( 'editor-color-palette', array( $wordpress_blue ) ); |
| | 327 | $response = self::perform_active_theme_request(); |
| | 328 | |
| | 329 | $result = $response->get_data(); |
| | 330 | $this->assertTrue( isset( $result[0]['theme_supports'] ) ); |
| | 331 | $this->assertEquals( array( $wordpress_blue), $result[0]['theme_supports']['editor-color-palette'] ); |
| | 332 | } |
| | 333 | |
| 298 | 334 | /** |
| 299 | 335 | * It should be possible to register custom fields to the endpoint. |
| 300 | 336 | * |