-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only display featured image UI when theme supports it too
- Loading branch information
1 parent
7b62a34
commit 5f392f6
Showing
2 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters