Make WordPress Core


Ignore:
Timestamp:
06/25/2020 10:11:09 PM (6 years ago)
Author:
TimothyBlynJacobs
Message:

Themes: Introduce register_theme_feature API.

Currently themes can declare support for a given feature by using add_theme_support(). This commit adds a register_theme_feature() API that allows plugins and WordPress Core to declare a list of available features that themes can support.

The REST API uses this to expose a theme's supported features if the feature has been registered with "show_in_rest" set to true.

Props kadamwhite, spacedmonkey, williampatton, desrosj, TimothyBlynJacobs.
Fixes #49406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r47921 r48171  
    261261
    262262                $theme_supports = $properties['theme_supports']['properties'];
    263                 $this->assertEquals( 20, count( $theme_supports ) );
    264263                $this->assertArrayHasKey( 'align-wide', $theme_supports );
    265264                $this->assertArrayHasKey( 'automatic-feed-links', $theme_supports );
     
    282281                $this->assertArrayHasKey( 'title-tag', $theme_supports );
    283282                $this->assertArrayHasKey( 'wp-block-styles', $theme_supports );
     283                $this->assertCount( 20, $theme_supports );
    284284        }
    285285
     
    999999
    10001000        /**
     1001         * @ticket 49406
     1002         */
     1003        public function test_variadic_theme_support() {
     1004                register_theme_feature(
     1005                        'test-feature',
     1006                        array(
     1007                                'type'         => 'array',
     1008                                'variadic'     => true,
     1009                                'show_in_rest' => array(
     1010                                        'schema' => array(
     1011                                                'items' => array(
     1012                                                        'type' => 'string',
     1013                                                ),
     1014                                        ),
     1015                                ),
     1016                        )
     1017                );
     1018                add_theme_support( 'test-feature', 'a', 'b', 'c' );
     1019
     1020                $response = self::perform_active_theme_request();
     1021                $result   = $response->get_data();
     1022                $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     1023                $this->assertEquals( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] );
     1024        }
     1025
     1026        /**
    10011027         * It should be possible to register custom fields to the endpoint.
    10021028         *
Note: See TracChangeset for help on using the changeset viewer.