Make WordPress Core


Ignore:
Timestamp:
06/25/2020 10:11:09 PM (4 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/src/wp-includes/rest-api.php

    r48150 r48171  
    17801780    return $data;
    17811781}
     1782
     1783/**
     1784 * Sets the "additionalProperties" to false by default for all object definitions in the schema.
     1785 *
     1786 * @since 5.5.0
     1787 *
     1788 * @param array $schema The schema to modify.
     1789 * @return array The modified schema.
     1790 */
     1791function rest_default_additional_properties_to_false( $schema ) {
     1792    $type = (array) $schema['type'];
     1793
     1794    if ( in_array( 'object', $type, true ) ) {
     1795        if ( isset( $schema['properties'] ) ) {
     1796            foreach ( $schema['properties'] as $key => $child_schema ) {
     1797                $schema['properties'][ $key ] = rest_default_additional_properties_to_false( $child_schema );
     1798            }
     1799        }
     1800
     1801        if ( ! isset( $schema['additionalProperties'] ) ) {
     1802            $schema['additionalProperties'] = false;
     1803        }
     1804    }
     1805
     1806    if ( in_array( 'array', $type, true ) ) {
     1807        if ( isset( $schema['items'] ) ) {
     1808            $schema['items'] = rest_default_additional_properties_to_false( $schema['items'] );
     1809        }
     1810    }
     1811
     1812    return $schema;
     1813}
Note: See TracChangeset for help on using the changeset viewer.