Skip to content

Commit

Permalink
Only display featured image UI when theme supports it too
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Apr 30, 2018
1 parent 7b62a34 commit 5f392f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions editor/components/post-type-support-check/index.js
Original file line number Diff line number Diff line change
@@ -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 );
5 changes: 5 additions & 0 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5f392f6

Please sign in to comment.