-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
edit.js
34 lines (32 loc) · 882 Bytes
/
edit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* WordPress dependencies
*/
import { useEntityProp, useEntityId } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { ResponsiveWrapper } from '@wordpress/components';
function PostFeaturedImageDisplay() {
const [ featuredImage ] = useEntityProp(
'postType',
'post',
'featured_media'
);
const media = useSelect(
( select ) =>
featuredImage && select( 'core' ).getMedia( featuredImage ),
[ featuredImage ]
);
return media ? (
<ResponsiveWrapper
naturalWidth={ media.media_details.width }
naturalHeight={ media.media_details.height }
>
<img src={ media.source_url } alt="Post Featured Media" />
</ResponsiveWrapper>
) : null;
}
export default function PostFeaturedImageEdit() {
if ( ! useEntityId( 'postType', 'post' ) ) {
return 'Post Featured Image Placeholder';
}
return <PostFeaturedImageDisplay />;
}