Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only display featured image UI when theme supports it too #6541

Merged
merged 2 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion editor/components/post-featured-image/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
* Internal dependencies
*/
import PostTypeSupportCheck from '../post-type-support-check';
import ThemeSupportCheck from '../theme-support-check';

function PostFeaturedImageCheck( props ) {
return <PostTypeSupportCheck { ...props } supportKeys="thumbnail" />;
return (
<ThemeSupportCheck supportKeys="post-thumbnails">
<PostTypeSupportCheck { ...props } supportKeys="thumbnail" />
</ThemeSupportCheck>
);
}

export default PostFeaturedImageCheck;
28 changes: 28 additions & 0 deletions editor/components/theme-support-check/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* External dependencies
*/
import { get, some, castArray } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';

export function ThemeSupportCheck( { themeSupports, children, supportKeys } ) {
const isSupported = some(
castArray( supportKeys ), ( key ) => get( themeSupports, [ key ], false )
);

if ( ! isSupported ) {
return null;
}

return children;
}

export default withSelect( ( select ) => {
const { getThemeSupports } = select( 'core' );
return {
themeSupports: getThemeSupports(),
};
} )( ThemeSupportCheck );
38 changes: 38 additions & 0 deletions editor/components/theme-support-check/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
import { shallow } from 'enzyme';

/**
* Internal dependencies
*/
import { ThemeSupportCheck } from '../index';

describe( 'ThemeSupportCheck', () => {
it( 'should not render if there\'s no support check provided', () => {
const wrapper = shallow( <ThemeSupportCheck>foobar</ThemeSupportCheck> );
expect( wrapper.type() ).toBe( null );
} );

it( 'should render if post-thumbnails are supported', () => {
const themeSupports = {
'post-thumbnails': true,
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow( <ThemeSupportCheck
supportKeys={ supportKeys }
themeSupports={ themeSupports }>foobar</ThemeSupportCheck> );
expect( wrapper.type() ).not.toBe( null );
} );

it( 'should not render if theme doesn\'t support post-thumbnails', () => {
const themeSupports = {
'post-thumbnails': false,
};
const supportKeys = 'post-thumbnails';
const wrapper = shallow( <ThemeSupportCheck
supportKeys={ supportKeys }
themeSupports={ themeSupports }>foobar</ThemeSupportCheck> );
expect( wrapper.type() ).toBe( null );
} );
} );
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