From 25d8f7240e85b48d919eb181448ad048c5c03127 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 11 Feb 2020 02:00:07 +0000 Subject: [PATCH] REST API: List all core theme feature support details in /themes endpoint response. Fully list which first-party core theme features are supported in the /themes endpoint response. This brings the REST API themes controller's response more in line with the output of get_theme_support(). Props adamboro, apieschel, koke, spacedmonkey, TimothyBlynJacobs. See #49037. Built from https://develop.svn.wordpress.org/trunk@47258 git-svn-id: http://core.svn.wordpress.org/trunk@47058 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-themes-controller.php | 310 ++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 291 insertions(+), 21 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 1d86d9938a..87051db58e 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -110,20 +110,46 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { $fields = $this->get_fields_for_response( $request ); if ( in_array( 'theme_supports', $fields, true ) ) { - $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; + $item_schemas = $this->get_item_schema(); + $theme_supports = $item_schemas['properties']['theme_supports']['properties']; + foreach ( $theme_supports as $name => $schema ) { + if ( 'formats' === $name ) { + continue; + } - $data['theme_supports']['post-thumbnails'] = false; - $data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' ); - $post_thumbnails = get_theme_support( 'post-thumbnails' ); + if ( ! current_theme_supports( $name ) ) { + $data['theme_supports'][ $name ] = false; + continue; + } - if ( $post_thumbnails ) { - // $post_thumbnails can contain a nested array of post types. - // e.g. array( array( 'post', 'page' ) ). - $data['theme_supports']['post-thumbnails'] = is_array( $post_thumbnails ) ? $post_thumbnails[0] : true; + if ( 'boolean' === $schema['type'] ) { + $data['theme_supports'][ $name ] = true; + continue; + } + + $support = get_theme_support( $name ); + + 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]; + } + } + + $data['theme_supports'][ $name ] = rest_sanitize_value_from_schema( $support, $schema ); } + + $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; } $data = $this->add_additional_fields_to_object( $data, $request ); @@ -162,23 +188,267 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { 'properties' => array( 'theme_supports' => array( 'description' => __( 'Features supported by this theme.' ), - 'type' => 'array', + 'type' => 'object', 'readonly' => true, 'properties' => array( - 'formats' => 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 graidients.' ), + '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', - 'readonly' => true, + 'items' => array( + 'type' => 'string', + 'enum' => get_post_format_slugs(), + ), ), - 'post-thumbnails' => array( + '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( 'array', 'bool' ), - 'readonly' => true, + 'type' => array( 'boolean', 'array' ), + 'items' => array( + 'type' => 'string', + ), ), - 'responsive-embeds' => array( + 'responsive-embeds' => array( 'description' => __( 'Whether the theme supports responsive embedded content.' ), - 'type' => 'bool', - 'readonly' => true, + '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', ), ), ), diff --git a/wp-includes/version.php b/wp-includes/version.php index 617dd0a08b..a3c9204d1b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47257'; +$wp_version = '5.4-alpha-47258'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.