<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[48171] trunk: Themes: Introduce register_theme_feature API.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/48171">48171</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/48171","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>TimothyBlynJacobs</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-06-25 22:11:09 +0000 (Thu, 25 Jun 2020)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/49406">#49406</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiphp">trunk/src/wp-includes/rest-api.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestthemescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php</a></li>
<li><a href="#trunktestsphpunitteststhemephp">trunk/tests/phpunit/tests/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/src/wp-includes/default-filters.php   2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -470,6 +470,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'delete_attachment', '_delete_attachment_theme_mod' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_dependent_auto_drafts', 20, 3 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_action( 'setup_theme', 'create_initial_theme_features', 0 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Calendar widget cache.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'save_post', 'delete_get_calendar_cache' );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestthemescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php      2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php        2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -167,50 +167,38 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( rest_is_field_included( 'theme_supports', $fields ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $item_schemas   = $this->get_item_schema();
-                       $theme_supports = $item_schemas['properties']['theme_supports']['properties'];
-                       foreach ( $theme_supports as $name => $schema ) {
-                               if ( ! rest_is_field_included( "theme_supports.{$name}", $fields ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 foreach ( get_registered_theme_features() as $feature => $config ) {
+                               if ( ! is_array( $config['show_in_rest'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( 'formats' === $name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $name = $config['show_in_rest']['name'];
+
+                               if ( ! rest_is_field_included( "theme_supports.{$name}", $fields ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( ! current_theme_supports( $name ) ) {
-                                       $data['theme_supports'][ $name ] = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( ! current_theme_supports( $feature ) ) {
+                                       $data['theme_supports'][ $name ] = $config['show_in_rest']['schema']['default'];
</ins><span class="cx" style="display: block; padding: 0 10px">                                         continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( 'boolean' === $schema['type'] ) {
-                                       $data['theme_supports'][ $name ] = true;
-                                       continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $support = get_theme_support( $feature );
+
+                               if ( isset( $config['show_in_rest']['prepare_callback'] ) ) {
+                                       $prepare = $config['show_in_rest']['prepare_callback'];
+                               } else {
+                                       $prepare = array( $this, 'prepare_theme_support' );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $support = get_theme_support( $name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $prepared = $prepare( $support, $config, $feature, $request );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( is_array( $support ) ) {
-                                       // None of the Core theme supports have variadic args.
-                                       $support = $support[0];
-
-                                       // Core multi-type theme-support schema definitions always list boolean first.
-                                       if ( is_array( $schema['type'] ) && 'boolean' === $schema['type'][0] ) {
-                                               // Pass the non-boolean type through to the sanitizer, which cannot itself
-                                               // determine the intended type if the value is invalid (for example if an
-                                               // object includes non-safelisted properties).
-                                               $schema['type'] = $schema['type'][1];
-                                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( is_wp_error( $prepared ) ) {
+                                       continue;
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $data['theme_supports'][ $name ] = rest_sanitize_value_from_schema( $support, $schema );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $data['theme_supports'][ $name ] = $prepared;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       $formats = get_theme_support( 'post-formats' );
-                       $formats = is_array( $formats ) ? array_values( $formats[0] ) : array();
-                       $formats = array_merge( array( 'standard' ), $formats );
-
-                       $data['theme_supports']['formats'] = $formats;
</del><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $this->add_additional_fields_to_object( $data, $request );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -231,6 +219,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Prepares the theme support value for inclusion in the REST API response.
+        *
+        * @since 5.5.0
+        *
+        * @param mixed           $support The raw value from {@see get_theme_support()}
+        * @param array           $args    The feature's registration args.
+        * @param string          $feature The feature name.
+        * @param WP_REST_Request $request The request object.
+        * @return mixed The prepared support value.
+        */
+       protected function prepare_theme_support( $support, $args, $feature, $request ) {
+               $schema = $args['show_in_rest']['schema'];
+
+               if ( 'boolean' === $schema['type'] ) {
+                       return true;
+               }
+
+               if ( is_array( $support ) ) {
+                       if ( ! $args['variadic'] ) {
+                               $support = $support[0];
+                       }
+
+                       // Multi-type theme-support schema definitions always list boolean first.
+                       if ( is_array( $schema['type'] ) && 'boolean' === $schema['type'][0] ) {
+                               // Pass the non-boolean type through to the sanitizer, which cannot itself
+                               // determine the intended type if the value is invalid (for example if an
+                               // object includes non-safelisted properties). See #50300.
+                               $schema['type'] = $schema['type'][1];
+                       }
+               }
+
+               return rest_sanitize_value_from_schema( $support, $schema );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Retrieves the theme's schema, conforming to JSON Schema.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,267 +385,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'Features supported by this theme.' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        'type'        => 'object',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'readonly'    => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'properties'  => array(
-                                               'align-wide'                => array(
-                                                       'description' => __( 'Whether theme opts in to wide alignment CSS class.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'automatic-feed-links'      => array(
-                                                       'description' => __( 'Whether posts and comments RSS feed links are added to head.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'custom-header'             => array(
-                                                       'description'          => __( 'Custom header if defined by the theme.' ),
-                                                       'type'                 => array( 'boolean', 'object' ),
-                                                       'properties'           => array(
-                                                               'default-image'      => array(
-                                                                       'type'   => 'string',
-                                                                       'format' => 'uri',
-                                                               ),
-                                                               'random-default'     => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'width'              => array(
-                                                                       'type' => 'integer',
-                                                               ),
-                                                               'height'             => array(
-                                                                       'type' => 'integer',
-                                                               ),
-                                                               'flex-height'        => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'flex-width'         => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'default-text-color' => array(
-                                                                       'type' => 'string',
-                                                               ),
-                                                               'header-text'        => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'uploads'            => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'video'              => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                       ),
-                                                       'additionalProperties' => false,
-                                               ),
-                                               'custom-background'         => array(
-                                                       'description'          => __( 'Custom background if defined by the theme.' ),
-                                                       'type'                 => array( 'boolean', 'object' ),
-                                                       'properties'           => array(
-                                                               'default-image'      => array(
-                                                                       'type'   => 'string',
-                                                                       'format' => 'uri',
-                                                               ),
-                                                               'default-preset'     => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'default',
-                                                                               'fill',
-                                                                               'fit',
-                                                                               'repeat',
-                                                                               'custom',
-                                                                       ),
-                                                               ),
-                                                               'default-position-x' => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'left',
-                                                                               'center',
-                                                                               'right',
-                                                                       ),
-                                                               ),
-                                                               'default-position-y' => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'left',
-                                                                               'center',
-                                                                               'right',
-                                                                       ),
-                                                               ),
-                                                               'default-size'       => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'auto',
-                                                                               'contain',
-                                                                               'cover',
-                                                                       ),
-                                                               ),
-                                                               'default-repeat'     => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'repeat-x',
-                                                                               'repeat-y',
-                                                                               'repeat',
-                                                                               'no-repeat',
-                                                                       ),
-                                                               ),
-                                                               'default-attachment' => array(
-                                                                       'type' => 'string',
-                                                                       'enum' => array(
-                                                                               'scroll',
-                                                                               'fixed',
-                                                                       ),
-                                                               ),
-                                                               'default-color'      => array(
-                                                                       'type' => 'string',
-                                                               ),
-                                                       ),
-                                                       'additionalProperties' => false,
-                                               ),
-                                               'custom-logo'               => array(
-                                                       'description'          => __( 'Custom logo if defined by the theme.' ),
-                                                       'type'                 => array( 'boolean', 'object' ),
-                                                       'properties'           => array(
-                                                               'width'       => array(
-                                                                       'type' => 'integer',
-                                                               ),
-                                                               'height'      => array(
-                                                                       'type' => 'integer',
-                                                               ),
-                                                               'flex-width'  => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'flex-height' => array(
-                                                                       'type' => 'boolean',
-                                                               ),
-                                                               'header-text' => array(
-                                                                       'type'  => 'array',
-                                                                       'items' => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                               ),
-                                                       ),
-                                                       'additionalProperties' => false,
-                                               ),
-                                               'customize-selective-refresh-widgets' => array(
-                                                       'description' => __( 'Whether the theme enables Selective Refresh for Widgets being managed with the Customizer.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'dark-editor-style'         => array(
-                                                       'description' => __( 'Whether theme opts in to the dark editor style UI.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'disable-custom-colors'     => array(
-                                                       'description' => __( 'Whether the theme disables custom colors.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'disable-custom-font-sizes' => array(
-                                                       'description' => __( 'Whether the theme disables custom font sizes.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'disable-custom-gradients'  => array(
-                                                       'description' => __( 'Whether the theme disables custom gradients.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'editor-color-palette'      => array(
-                                                       'description' => __( 'Custom color palette if defined by the theme.' ),
-                                                       'type'        => array( 'boolean', 'array' ),
-                                                       'items'       => array(
-                                                               'type'                 => 'object',
-                                                               'properties'           => array(
-                                                                       'name'  => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                                       'slug'  => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                                       'color' => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                               ),
-                                                               'additionalProperties' => false,
-                                                       ),
-                                               ),
-                                               'editor-font-sizes'         => array(
-                                                       'description' => __( 'Custom font sizes if defined by the theme.' ),
-                                                       'type'        => array( 'boolean', 'array' ),
-                                                       'items'       => array(
-                                                               'type'                 => 'object',
-                                                               'properties'           => array(
-                                                                       'name' => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                                       'size' => array(
-                                                                               'type' => 'number',
-                                                                       ),
-                                                                       'slug' => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                               ),
-                                                               'additionalProperties' => false,
-                                                       ),
-                                               ),
-                                               'editor-gradient-presets'   => array(
-                                                       'description' => __( 'Custom gradient presets if defined by the theme.' ),
-                                                       'type'        => array( 'boolean', 'array' ),
-                                                       'items'       => array(
-                                                               'type'                 => 'object',
-                                                               'properties'           => array(
-                                                                       'name'     => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                                       'gradient' => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                                       'slug'     => array(
-                                                                               'type' => 'string',
-                                                                       ),
-                                                               ),
-                                                               'additionalProperties' => false,
-                                                       ),
-                                               ),
-                                               'editor-styles'             => array(
-                                                       'description' => __( 'Whether theme opts in to the editor styles CSS wrapper.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'formats'                   => array(
-                                                       'description' => __( 'Post formats supported.' ),
-                                                       'type'        => 'array',
-                                                       'items'       => array(
-                                                               'type' => 'string',
-                                                               'enum' => get_post_format_slugs(),
-                                                       ),
-                                               ),
-                                               'html5'                     => array(
-                                                       'description' => __( 'Allows use of html5 markup for search forms, comment forms, comment lists, gallery, and caption.' ),
-                                                       'type'        => array( 'boolean', 'array' ),
-                                                       'items'       => array(
-                                                               'type' => 'string',
-                                                               'enum' => array(
-                                                                       'search-form',
-                                                                       'comment-form',
-                                                                       'comment-list',
-                                                                       'gallery',
-                                                                       'caption',
-                                                                       'script',
-                                                                       'style',
-                                                               ),
-                                                       ),
-                                               ),
-                                               'post-thumbnails'           => array(
-                                                       'description' => __( 'Whether the theme supports post thumbnails.' ),
-                                                       'type'        => array( 'boolean', 'array' ),
-                                                       'items'       => array(
-                                                               'type' => 'string',
-                                                       ),
-                                               ),
-                                               'responsive-embeds'         => array(
-                                                       'description' => __( 'Whether the theme supports responsive embedded content.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'title-tag'                 => array(
-                                                       'description' => __( 'Whether the theme can manage the document title tag.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                               'wp-block-styles'           => array(
-                                                       'description' => __( 'Whether theme opts in to default WordPress block styles for viewing.' ),
-                                                       'type'        => 'boolean',
-                                               ),
-                                       ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'properties'  => array(),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'theme_uri'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'description' => __( 'The URI of the theme\'s webpage.' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -649,6 +412,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                foreach ( get_registered_theme_features() as $feature => $config ) {
+                       if ( ! is_array( $config['show_in_rest'] ) ) {
+                               continue;
+                       }
+
+                       $name = $config['show_in_rest']['name'];
+
+                       $schema['properties']['theme_supports']['properties'][ $name ] = $config['show_in_rest']['schema'];
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->schema = $schema;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $this->add_additional_fields_schema( $this->schema );
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api.php        2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/src/wp-includes/rest-api.php  2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1779,3 +1779,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return $data;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Sets the "additionalProperties" to false by default for all object definitions in the schema.
+ *
+ * @since 5.5.0
+ *
+ * @param array $schema The schema to modify.
+ * @return array The modified schema.
+ */
+function rest_default_additional_properties_to_false( $schema ) {
+       $type = (array) $schema['type'];
+
+       if ( in_array( 'object', $type, true ) ) {
+               if ( isset( $schema['properties'] ) ) {
+                       foreach ( $schema['properties'] as $key => $child_schema ) {
+                               $schema['properties'][ $key ] = rest_default_additional_properties_to_false( $child_schema );
+                       }
+               }
+
+               if ( ! isset( $schema['additionalProperties'] ) ) {
+                       $schema['additionalProperties'] = false;
+               }
+       }
+
+       if ( in_array( 'array', $type, true ) ) {
+               if ( isset( $schema['items'] ) ) {
+                       $schema['items'] = rest_default_additional_properties_to_false( $schema['items'] );
+               }
+       }
+
+       return $schema;
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme.php   2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/src/wp-includes/theme.php     2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2994,6 +2994,156 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Registers a theme feature for use in {@see add_theme_support}.
+ *
+ * This does not indicate that the current theme supports the feature, it only describes the feature's supported options.
+ *
+ * @since 5.5.0
+ *
+ * @global $_wp_registered_theme_features
+ *
+ * @param string $feature The name uniquely identifying the feature.
+ * @param array $args {
+ *      Data used to describe the theme
+ *
+ *      @type string     $type         The type of data associated with this feature. Defaults to 'boolean'.
+ *                                     Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
+ *      @type boolean    $variadic     Does this feature utilize the variadic support of {@see add_theme_support()},
+ *                                     or are all arguments specified as the second parameter. Must be used with the "array" type.
+ *      @type string     $description  A short description of the feature. Included in the Themes REST API schema. Intended for developers.
+ *      @type bool|array $show_in_rest {
+ *          Whether this feature should be included in the Themes REST API endpoint. Defaults to not being included.
+ *          When registering an 'array' or 'object' type, this argument must be an array with the 'schema' key.
+ *
+ *          @type array    $schema           Specifies the JSON Schema definition describing the feature. If any objects in the schema
+ *                                           do not include the 'additionalProperties' keyword, it is set to false.
+ *          @type string   $name             An alternate name to be use as the property name in the REST API.
+ *          @type callable $prepare_callback A function used to format the theme support in the REST API. Receives the raw theme support value.
+ *      }
+ * }
+ * @return true|WP_Error True if the theme feature was successfully registered, a WP_Error object if not.
+ */
+function register_theme_feature( $feature, $args = array() ) {
+       global $_wp_registered_theme_features;
+
+       if ( ! is_array( $_wp_registered_theme_features ) ) {
+               $_wp_registered_theme_features = array();
+       }
+
+       $defaults = array(
+               'type'         => 'boolean',
+               'variadic'     => false,
+               'description'  => '',
+               'show_in_rest' => false,
+       );
+
+       $args = wp_parse_args( $args, $defaults );
+
+       if ( true === $args['show_in_rest'] ) {
+               $args['show_in_rest'] = array();
+       }
+
+       if ( is_array( $args['show_in_rest'] ) ) {
+               $args['show_in_rest'] = wp_parse_args(
+                       $args['show_in_rest'],
+                       array(
+                               'schema'           => array(),
+                               'name'             => $feature,
+                               'prepare_callback' => null,
+                       )
+               );
+       }
+
+       if ( ! in_array( $args['type'], array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
+               return new WP_Error( 'invalid_type', __( 'The feature "type" is not valid JSON Schema type.' ) );
+       }
+
+       if ( true === $args['variadic'] && 'array' !== $args['type'] ) {
+               return new WP_Error( 'variadic_must_be_array', __( 'When registering a "variadic" theme feature, the "type" must be an "array".' ) );
+       }
+
+       if ( false !== $args['show_in_rest'] && in_array( $args['type'], array( 'array', 'object' ), true ) ) {
+               if ( ! is_array( $args['show_in_rest'] ) || empty( $args['show_in_rest']['schema'] ) ) {
+                       return new WP_Error( 'missing_schema', __( 'When registering an "array" or "object" feature to show in the REST API, the feature\'s schema must also be defined.' ) );
+               }
+
+               if ( 'array' === $args['type'] && ! isset( $args['show_in_rest']['schema']['items'] ) ) {
+                       return new WP_Error( 'missing_schema_items', __( 'When registering an "array" feature, the feature\'s schema must include the "items" keyword.' ) );
+               }
+
+               if ( 'object' === $args['type'] && ! isset( $args['show_in_rest']['schema']['properties'] ) ) {
+                       return new WP_Error( 'missing_schema_properties', __( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' ) );
+               }
+       }
+
+       if ( is_array( $args['show_in_rest'] ) ) {
+               if ( isset( $args['show_in_rest']['prepare_callback'] ) && ! is_callable( $args['show_in_rest']['prepare_callback'] ) ) {
+                       return new WP_Error( 'invalid_rest_prepare_callback', __( 'The prepare_callback must be a callable function.' ) );
+               }
+
+               $args['show_in_rest']['schema'] = wp_parse_args(
+                       $args['show_in_rest']['schema'],
+                       array(
+                               'description' => $args['description'],
+                               'type'        => $args['type'],
+                               'default'     => false,
+                       )
+               );
+
+               if ( is_bool( $args['show_in_rest']['schema']['default'] ) && ! in_array( 'boolean', (array) $args['show_in_rest']['schema']['type'], true ) ) {
+                       // Automatically include the "boolean" type when the default value is a boolean.
+                       $args['show_in_rest']['schema']['type'] = (array) $args['show_in_rest']['schema']['type'];
+                       array_unshift( $args['show_in_rest']['schema']['type'], 'boolean' );
+               }
+
+               $args['show_in_rest']['schema'] = rest_default_additional_properties_to_false( $args['show_in_rest']['schema'] );
+       }
+
+       $_wp_registered_theme_features[ $feature ] = $args;
+
+       return true;
+}
+
+/**
+ * Gets the list of registered theme features.
+ *
+ * @since 5.5.0
+ *
+ * @global $_wp_registered_theme_features
+ *
+ * @return array[] List of theme features, keyed by their name.
+ */
+function get_registered_theme_features() {
+       global $_wp_registered_theme_features;
+
+       if ( ! is_array( $_wp_registered_theme_features ) ) {
+               return array();
+       }
+
+       return $_wp_registered_theme_features;
+}
+
+/**
+ * Gets the registration config for a theme feature.
+ *
+ * @since 5.5.0
+ *
+ * @global $_wp_registered_theme_features
+ *
+ * @param string $feature The feature name.
+ * @return array|null The registration args, or null if the feature was not registered.
+ */
+function get_registered_theme_feature( $feature ) {
+       global $_wp_registered_theme_features;
+
+       if ( ! is_array( $_wp_registered_theme_features ) ) {
+               return null;
+       }
+
+       return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Checks an attachment being deleted to see if it's a header or background image.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * If true it removes the theme modification which would be pointing at the deleted
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3462,3 +3612,371 @@
</span><span class="cx" style="display: block; padding: 0 10px">                clean_post_cache( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Creates the initial theme features when the 'setup_theme' action is fired.
+ *
+ * See {@see 'setup_theme'}.
+ *
+ * @since 5.5.0
+ */
+function create_initial_theme_features() {
+       register_theme_feature(
+               'align-wide',
+               array(
+                       'description'  => __( 'Whether theme opts in to wide alignment CSS class.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'automatic-feed-links',
+               array(
+                       'description'  => __( 'Whether posts and comments RSS feed links are added to head.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'custom-background',
+               array(
+                       'description'  => __( 'Custom background if defined by the theme.' ),
+                       'type'         => 'object',
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'properties' => array(
+                                               'default-image'      => array(
+                                                       'type'   => 'string',
+                                                       'format' => 'uri',
+                                               ),
+                                               'default-preset'     => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'default',
+                                                               'fill',
+                                                               'fit',
+                                                               'repeat',
+                                                               'custom',
+                                                       ),
+                                               ),
+                                               'default-position-x' => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'left',
+                                                               'center',
+                                                               'right',
+                                                       ),
+                                               ),
+                                               'default-position-y' => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'left',
+                                                               'center',
+                                                               'right',
+                                                       ),
+                                               ),
+                                               'default-size'       => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'auto',
+                                                               'contain',
+                                                               'cover',
+                                                       ),
+                                               ),
+                                               'default-repeat'     => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'repeat-x',
+                                                               'repeat-y',
+                                                               'repeat',
+                                                               'no-repeat',
+                                                       ),
+                                               ),
+                                               'default-attachment' => array(
+                                                       'type' => 'string',
+                                                       'enum' => array(
+                                                               'scroll',
+                                                               'fixed',
+                                                       ),
+                                               ),
+                                               'default-color'      => array(
+                                                       'type' => 'string',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'custom-header',
+               array(
+                       'description'  => __( 'Custom header if defined by the theme.' ),
+                       'type'         => 'object',
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'properties' => array(
+                                               'default-image'      => array(
+                                                       'type'   => 'string',
+                                                       'format' => 'uri',
+                                               ),
+                                               'random-default'     => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'width'              => array(
+                                                       'type' => 'integer',
+                                               ),
+                                               'height'             => array(
+                                                       'type' => 'integer',
+                                               ),
+                                               'flex-height'        => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'flex-width'         => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'default-text-color' => array(
+                                                       'type' => 'string',
+                                               ),
+                                               'header-text'        => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'uploads'            => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'video'              => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'custom-logo',
+               array(
+                       'type'         => 'object',
+                       'description'  => __( 'Custom logo if defined by the theme.' ),
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'properties' => array(
+                                               'width'       => array(
+                                                       'type' => 'integer',
+                                               ),
+                                               'height'      => array(
+                                                       'type' => 'integer',
+                                               ),
+                                               'flex-width'  => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'flex-height' => array(
+                                                       'type' => 'boolean',
+                                               ),
+                                               'header-text' => array(
+                                                       'type'  => 'array',
+                                                       'items' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'customize-selective-refresh-widgets',
+               array(
+                       'description'  => __( 'Whether the theme enables Selective Refresh for Widgets being managed with the Customizer.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'dark-editor-style',
+               array(
+                       'description'  => __( 'Whether theme opts in to the dark editor style UI.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'disable-custom-colors',
+               array(
+                       'description'  => __( 'Whether the theme disables custom colors.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'disable-custom-font-sizes',
+               array(
+                       'description'  => __( 'Whether the theme disables custom font sizes.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'disable-custom-gradients',
+               array(
+                       'description'  => __( 'Whether the theme disables custom gradients.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'editor-color-palette',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'Custom color palette if defined by the theme.' ),
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'items' => array(
+                                               'type'       => 'object',
+                                               'properties' => array(
+                                                       'name'  => array(
+                                                               'type' => 'string',
+                                                       ),
+                                                       'slug'  => array(
+                                                               'type' => 'string',
+                                                       ),
+                                                       'color' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'editor-font-sizes',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'Custom font sizes if defined by the theme.' ),
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'items' => array(
+                                               'type'       => 'object',
+                                               'properties' => array(
+                                                       'name' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                                       'size' => array(
+                                                               'type' => 'number',
+                                                       ),
+                                                       'slug' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'editor-gradient-presets',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'Custom gradient presets if defined by the theme.' ),
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'items' => array(
+                                               'type'       => 'object',
+                                               'properties' => array(
+                                                       'name'     => array(
+                                                               'type' => 'string',
+                                                       ),
+                                                       'gradient' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                                       'slug'     => array(
+                                                               'type' => 'string',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'editor-styles',
+               array(
+                       'description'  => __( 'Whether theme opts in to the editor styles CSS wrapper.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'html5',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption.' ),
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'items' => array(
+                                               'type' => 'string',
+                                               'enum' => array(
+                                                       'search-form',
+                                                       'comment-form',
+                                                       'comment-list',
+                                                       'gallery',
+                                                       'caption',
+                                                       'script',
+                                                       'style',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'post-formats',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'Post formats supported.' ),
+                       'show_in_rest' => array(
+                               'name'             => 'formats',
+                               'schema'           => array(
+                                       'items'   => array(
+                                               'type' => 'string',
+                                               'enum' => get_post_format_slugs(),
+                                       ),
+                                       'default' => array( 'standard' ),
+                               ),
+                               'prepare_callback' => static function ( $formats ) {
+                                       $formats = is_array( $formats ) ? array_values( $formats[0] ) : array();
+                                       $formats = array_merge( array( 'standard' ), $formats );
+
+                                       return $formats;
+                               },
+                       ),
+               )
+       );
+       register_theme_feature(
+               'post-thumbnails',
+               array(
+                       'type'         => 'array',
+                       'description'  => __( 'The post types that support thumbnails or true if all post types are supported.' ),
+                       'show_in_rest' => array(
+                               'type'   => array( 'boolean', 'array' ),
+                               'schema' => array(
+                                       'items' => array(
+                                               'type' => 'string',
+                                       ),
+                               ),
+                       ),
+               )
+       );
+       register_theme_feature(
+               'responsive-embeds',
+               array(
+                       'description'  => __( 'Whether the theme supports responsive embedded content.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'title-tag',
+               array(
+                       'description'  => __( 'Whether the theme can manage the document title tag.' ),
+                       'show_in_rest' => true,
+               )
+       );
+       register_theme_feature(
+               'wp-block-styles',
+               array(
+                       'description'  => __( 'Whether theme opts in to default WordPress block styles for viewing.' ),
+                       'show_in_rest' => true,
+               )
+       );
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsrestapirestthemescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php     2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php       2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -260,7 +260,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'version', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $theme_supports = $properties['theme_supports']['properties'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 20, count( $theme_supports ) );
</del><span class="cx" style="display: block; padding: 0 10px">                 $this->assertArrayHasKey( 'align-wide', $theme_supports );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'automatic-feed-links', $theme_supports );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'custom-header', $theme_supports );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -281,6 +280,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'responsive-embeds', $theme_supports );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'title-tag', $theme_supports );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertArrayHasKey( 'wp-block-styles', $theme_supports );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertCount( 20, $theme_supports );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -998,6 +998,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 49406
+        */
+       public function test_variadic_theme_support() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'array',
+                               'variadic'     => true,
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'items' => array(
+                                                       'type' => 'string',
+                                               ),
+                                       ),
+                               ),
+                       )
+               );
+               add_theme_support( 'test-feature', 'a', 'b', 'c' );
+
+               $response = self::perform_active_theme_request();
+               $result   = $response->get_data();
+               $this->assertTrue( isset( $result[0]['theme_supports'] ) );
+               $this->assertEquals( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * It should be possible to register custom fields to the endpoint.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 45016
</span></span></pre></div>
<a id="trunktestsphpunitteststhemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme.php       2020-06-25 18:43:25 UTC (rev 48170)
+++ trunk/tests/phpunit/tests/theme.php 2020-06-25 22:11:09 UTC (rev 48171)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -415,4 +415,288 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'trash', get_post_status( $nav_created_post_ids[0] ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'private', get_post_status( $nav_created_post_ids[1] ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_defaults() {
+               $registered = register_theme_feature( 'test-feature' );
+               $this->assertTrue( $registered );
+
+               $expected = array(
+                       'type'         => 'boolean',
+                       'variadic'     => false,
+                       'description'  => '',
+                       'show_in_rest' => false,
+               );
+               $this->assertEqualSets( $expected, get_registered_theme_feature( 'test-feature' ) );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_explicit() {
+               $args = array(
+                       'type'         => 'array',
+                       'variadic'     => true,
+                       'description'  => 'My Feature',
+                       'show_in_rest' => array(
+                               'schema' => array(
+                                       'items' => array(
+                                               'type' => 'string',
+                                       ),
+                               ),
+                       ),
+               );
+
+               register_theme_feature( 'test-feature', $args );
+               $actual = get_registered_theme_feature( 'test-feature' );
+
+               $this->assertEquals( 'array', $actual['type'] );
+               $this->assertTrue( $actual['variadic'] );
+               $this->assertEquals( 'My Feature', $actual['description'] );
+               $this->assertEquals( array( 'type' => 'string' ), $actual['show_in_rest']['schema']['items'] );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_upgrades_show_in_rest() {
+               register_theme_feature( 'test-feature', array( 'show_in_rest' => true ) );
+
+               $expected = array(
+                       'schema'           => array(
+                               'type'        => 'boolean',
+                               'description' => '',
+                               'default'     => false,
+                       ),
+                       'name'             => 'test-feature',
+                       'prepare_callback' => null,
+               );
+               $actual   = get_registered_theme_feature( 'test-feature' )['show_in_rest'];
+
+               $this->assertEqualSets( $expected, $actual );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_fills_schema() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'array',
+                               'description'  => 'Cool Feature',
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'items'    => array(
+                                                       'type' => 'string',
+                                               ),
+                                               'minItems' => 1,
+                                       ),
+                               ),
+                       )
+               );
+
+               $expected = array(
+                       'description' => 'Cool Feature',
+                       'type'        => array( 'boolean', 'array' ),
+                       'items'       => array(
+                               'type' => 'string',
+                       ),
+                       'minItems'    => 1,
+                       'default'     => false,
+               );
+               $actual   = get_registered_theme_feature( 'test-feature' )['show_in_rest']['schema'];
+
+               $this->assertEqualSets( $expected, $actual );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_does_not_add_boolean_type_if_non_bool_default() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'array',
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'items'   => array(
+                                                       'type' => 'string',
+                                               ),
+                                               'default' => array( 'standard' ),
+                                       ),
+                               ),
+                       )
+               );
+
+               $actual = get_registered_theme_feature( 'test-feature' )['show_in_rest']['schema']['type'];
+               $this->assertEquals( 'array', $actual );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_defaults_additional_properties_to_false() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'object',
+                               'description'  => 'Cool Feature',
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'properties' => array(
+                                                       'a' => array(
+                                                               'type' => 'string',
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       )
+               );
+
+               $actual = get_registered_theme_feature( 'test-feature' )['show_in_rest']['schema'];
+
+               $this->assertArrayHasKey( 'additionalProperties', $actual );
+               $this->assertFalse( $actual['additionalProperties'] );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_with_additional_properties() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'object',
+                               'description'  => 'Cool Feature',
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'properties'           => array(),
+                                               'additionalProperties' => array(
+                                                       'type' => 'string',
+                                               ),
+                                       ),
+                               ),
+                       )
+               );
+
+               $expected = array(
+                       'type' => 'string',
+               );
+               $actual   = get_registered_theme_feature( 'test-feature' )['show_in_rest']['schema']['additionalProperties'];
+
+               $this->assertEqualSets( $expected, $actual );
+       }
+
+       /**
+        * @ticket 49406
+        */
+       public function test_register_theme_support_defaults_additional_properties_to_false_in_array() {
+               register_theme_feature(
+                       'test-feature',
+                       array(
+                               'type'         => 'array',
+                               'description'  => 'Cool Feature',
+                               'show_in_rest' => array(
+                                       'schema' => array(
+                                               'items' => array(
+                                                       'type'       => 'object',
+                                                       'properties' => array(
+                                                               'a' => array(
+                                                                       'type' => 'string',
+                                                               ),
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                       )
+               );
+
+               $actual = get_registered_theme_feature( 'test-feature' )['show_in_rest']['schema']['items'];
+
+               $this->assertArrayHasKey( 'additionalProperties', $actual );
+               $this->assertFalse( $actual['additionalProperties'] );
+       }
+
+       /**
+        * @ticket       49406
+        * @dataProvider _dp_register_theme_support_validation
+        * @param string $error_code The error code expected.
+        * @param array  $args       The args to register.
+        */
+       public function test_register_theme_support_validation( $error_code, $args ) {
+               $registered = register_theme_feature( 'test-feature', $args );
+
+               $this->assertWPError( $registered );
+               $this->assertEquals( $error_code, $registered->get_error_code() );
+       }
+
+       public function _dp_register_theme_support_validation() {
+               return array(
+                       array(
+                               'invalid_type',
+                               array(
+                                       'type' => 'float',
+                               ),
+                       ),
+                       array(
+                               'invalid_type',
+                               array(
+                                       'type' => array( 'string' ),
+                               ),
+                       ),
+                       array(
+                               'variadic_must_be_array',
+                               array(
+                                       'variadic' => true,
+                               ),
+                       ),
+                       array(
+                               'missing_schema',
+                               array(
+                                       'type'         => 'object',
+                                       'show_in_rest' => true,
+                               ),
+                       ),
+                       array(
+                               'missing_schema',
+                               array(
+                                       'type'         => 'array',
+                                       'show_in_rest' => true,
+                               ),
+                       ),
+                       array(
+                               'missing_schema_items',
+                               array(
+                                       'type'         => 'array',
+                                       'show_in_rest' => array(
+                                               'schema' => array(
+                                                       'type' => 'array',
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       array(
+                               'missing_schema_properties',
+                               array(
+                                       'type'         => 'object',
+                                       'show_in_rest' => array(
+                                               'schema' => array(
+                                                       'type' => 'object',
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       array(
+                               'invalid_rest_prepare_callback',
+                               array(
+                                       'show_in_rest' => array(
+                                               'prepare_callback' => 'this is not a valid function',
+                                       ),
+                               ),
+                       ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>