-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataViews: Add featured image field to the page list (#55246)
Co-authored-by: ntsekouras <ntsekouras@outlook.com>
- Loading branch information
1 parent
00d1226
commit bc47191
Showing
4 changed files
with
49 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityRecord } from '@wordpress/core-data'; | ||
|
||
function Media( { id, size, ...props } ) { | ||
const { record: media } = useEntityRecord( 'root', 'media', id ); | ||
const sizesPerPriority = [ 'large', 'thumbnail' ]; | ||
const currentSize = | ||
size ?? | ||
sizesPerPriority.find( ( s ) => !! media?.media_details?.sizes[ s ] ); | ||
const mediaDetails = media?.media_details?.sizes[ currentSize ]; | ||
|
||
if ( ! mediaDetails ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<img | ||
{ ...props } | ||
src={ mediaDetails.source_url } | ||
alt={ media.alt_text } | ||
/> | ||
); | ||
} | ||
|
||
export default Media; |
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.edit-site-page-pages__featured-image { | ||
border-radius: $radius-block-ui; | ||
max-height: 60px; | ||
} |
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