Skip to content

Commit

Permalink
Fix default featured image size (#15844)
Browse files Browse the repository at this point in the history
* Change featured image default size to thumnail

* fallbackMediaSize added to featured image

mediaSize reset to post-thumbnail
fallbackMediaSize added and set to thumbnail

`editor.PostFeaturedImage.fallbackImageSize` filter added to modify the new fallbackMediaSize

* PostFeaturedImage Performance optimizations

improved: the fallback size will now be calculated only if the default size is not available.
changed: the fallback size now uses the same filter as the default size


Co-authored-by: Julian Weiland <[email protected]>
Co-authored-by: Werbeagenten <[email protected]>
  • Loading branch information
3 people authored and jorgefilipecosta committed Nov 4, 2019
1 parent 38da131 commit 61753df
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/editor/src/components/post-featured-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ function PostFeaturedImage( { currentPostId, featuredImageId, onUpdateImage, onR
if ( media ) {
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'post-thumbnail', media.id, currentPostId );
if ( has( media, [ 'media_details', 'sizes', mediaSize ] ) ) {
// use mediaSize when available
mediaWidth = media.media_details.sizes[ mediaSize ].width;
mediaHeight = media.media_details.sizes[ mediaSize ].height;
mediaSourceUrl = media.media_details.sizes[ mediaSize ].source_url;
} else {
mediaWidth = media.media_details.width;
mediaHeight = media.media_details.height;
mediaSourceUrl = media.source_url;
// get fallbackMediaSize if mediaSize is not available
const fallbackMediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'thumbnail', media.id, currentPostId );
if ( has( media, [ 'media_details', 'sizes', fallbackMediaSize ] ) ) {
// use fallbackMediaSize when mediaSize is not available
mediaWidth = media.media_details.sizes[ fallbackMediaSize ].width;
mediaHeight = media.media_details.sizes[ fallbackMediaSize ].height;
mediaSourceUrl = media.media_details.sizes[ fallbackMediaSize ].source_url;
} else {
// use full image size when mediaFallbackSize and mediaSize are not available
mediaWidth = media.media_details.width;
mediaHeight = media.media_details.height;
mediaSourceUrl = media.source_url;
}
}
}

Expand Down

0 comments on commit 61753df

Please sign in to comment.