diff --git a/editor/components/post-type-support-check/index.js b/editor/components/post-type-support-check/index.js index 02156e287d684..c029783fe64cd 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 9bf014d718e4a..97bdd87ce831b 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; }