From 5f392f62a6c2038c58ca5155d86639f20db4f930 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 30 Apr 2018 15:54:07 -0700 Subject: [PATCH] Only display featured image UI when theme supports it too --- .../components/post-type-support-check/index.js | 16 ++++++++++++---- lib/rest-api.php | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/editor/components/post-type-support-check/index.js b/editor/components/post-type-support-check/index.js index 02156e287d6843..c029783fe64cd3 100644 --- a/editor/components/post-type-support-check/index.js +++ b/editor/components/post-type-support-check/index.js @@ -1,29 +1,37 @@ /** * External dependencies */ -import { get, some, castArray } from 'lodash'; +import { get, includes, some, castArray } from 'lodash'; /** * WordPress dependencies */ import { withSelect } from '@wordpress/data'; -function PostTypeSupportCheck( { postType, children, supportKeys } ) { +function PostTypeSupportCheck( { postType, children, supportKeys, themeSupports } ) { + supportKeys = castArray( supportKeys ); const isSupported = some( - castArray( supportKeys ), ( key ) => get( postType, [ 'supports', key ], false ) + supportKeys, ( key ) => get( postType, [ 'supports', key ], false ) ); if ( ! isSupported ) { return null; } + // 'thumbnail' and 'post-thumbnails' are intentionally different. + if ( includes( supportKeys, 'thumbnail' ) + && ! get( themeSupports, 'post-thumbnails', false ) ) { + return null; + } + return children; } export default withSelect( ( select ) => { const { getEditedPostAttribute } = select( 'core/editor' ); - const { getPostType } = select( 'core' ); + const { getPostType, getThemeSupports } = select( 'core' ); return { + themeSupports: getThemeSupports(), postType: getPostType( getEditedPostAttribute( 'type' ) ), }; } )( PostTypeSupportCheck ); diff --git a/lib/rest-api.php b/lib/rest-api.php index 9bf014d718e4a2..97bdd87ce831b1 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -370,6 +370,11 @@ function gutenberg_ensure_wp_json_has_theme_supports( $response ) { $site_info['theme_supports']['formats'] = $formats; } + if ( ! array_key_exists( 'post-thumbnails', $site_info['theme_supports'] ) ) { + if ( get_theme_support( 'post-thumbnails' ) ) { + $site_info['theme_supports']['post-thumbnails'] = true; + } + } $response->set_data( $site_info ); return $response; }