Make WordPress Core

Changeset 55951


Ignore:
Timestamp:
06/20/2023 10:15:57 PM (17 months ago)
Author:
audrasjb
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r53760 r55951  
    327327        }
    328328
     329        if ( rest_is_field_included( 'is_block_theme', $fields ) ) {
     330            $data['is_block_theme'] = $theme->is_block_theme();
     331        }
     332
    329333        $data = $this->add_additional_fields_to_object( $data, $request );
    330334
     
    495499                    ),
    496500                ),
     501                'is_block_theme' => array(
     502                    'description' => __( 'Whether the theme is a block-based theme.' ),
     503                    'type'        => 'boolean',
     504                    'readonly'    => true,
     505                ),
    497506                'name'           => array(
    498507                    'description' => __( 'The name of the theme.' ),
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r55822 r55951  
    173173            'author_uri',
    174174            'description',
     175            'is_block_theme',
    175176            'name',
    176177            'requires_php',
     
    186187            'version',
    187188        );
     189        $this->assertIsArray( $data );
     190        $this->assertNotEmpty( $data );
    188191        $this->assertSameSets( $fields, array_keys( $data[0] ) );
    189192    }
     
    209212            'author_uri',
    210213            'description',
     214            'is_block_theme',
    211215            'name',
    212216            'requires_php',
     
    221225            'version',
    222226        );
     227        $this->assertIsArray( $data );
     228        $this->assertNotEmpty( $data );
    223229        $this->assertSameSets( $fields, array_keys( $data[0] ) );
    224230
     
    344350        $data       = $response->get_data();
    345351        $properties = $data['schema']['properties'];
    346         $this->assertCount( 15, $properties );
     352        $this->assertCount( 16, $properties );
    347353
    348354        $this->assertArrayHasKey( 'author', $properties );
     
    357363        $this->assertArrayHasKey( 'raw', $properties['description']['properties'] );
    358364        $this->assertArrayHasKey( 'rendered', $properties['description']['properties'] );
     365
     366        $this->assertArrayHasKey( 'is_block_theme', $properties );
    359367
    360368        $this->assertArrayHasKey( 'name', $properties );
     
    473481
    474482    /**
     483     * @ticket 58123
     484     * @covers WP_REST_Themes_Controller::prepare_item_for_response
     485     */
     486    public function test_theme_is_block_theme() {
     487        // Test classic theme, activated in test setup.
     488        $response = self::perform_active_theme_request();
     489        $result   = $response->get_data();
     490
     491        $this->assertArrayHasKey( 'is_block_theme', $result[0] );
     492        $this->assertFalse( $result[0]['is_block_theme'] );
     493
     494        // Test block theme.
     495        switch_theme( 'block-theme' );
     496        $response = self::perform_active_theme_request();
     497        $result   = $response->get_data();
     498
     499        $this->assertArrayHasKey( 'is_block_theme', $result[0] );
     500        $this->assertTrue( $result[0]['is_block_theme'] );
     501    }
     502
     503    /**
    475504     * @ticket 49906
    476505     */
     
    12351264            'author_uri',
    12361265            'description',
     1266            'is_block_theme',
    12371267            'name',
    12381268            'requires_php',
Note: See TracChangeset for help on using the changeset viewer.