Skip to content

Commit

Permalink
Cover: Fix media library image selection (#66782)
Browse files Browse the repository at this point in the history
* Cover: Fix media library image selection
* Fix sizes for uploaded images

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
  • Loading branch information
4 people authored Nov 6, 2024
1 parent 471e4bd commit 7ff7679
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,24 @@ function CoverEdit( {

// Try to use the previous selected image size if it's available
// otherwise try the default image size or fallback to full size.
if ( sizeSlug && newMedia?.sizes?.[ sizeSlug ] ) {
if (
sizeSlug &&
( newMedia?.sizes?.[ sizeSlug ] ||
newMedia?.media_details?.sizes?.[ sizeSlug ] )
) {
mediaAttributes.sizeSlug = sizeSlug;
mediaAttributes.url = newMedia?.sizes?.[ sizeSlug ]?.url;
} else if ( newMedia?.sizes?.[ imageDefaultSize ] ) {
mediaAttributes.url =
newMedia?.sizes?.[ sizeSlug ]?.url ||
newMedia?.media_details?.sizes?.[ sizeSlug ]?.source_url;
} else if (
newMedia?.sizes?.[ imageDefaultSize ] ||
newMedia?.media_details?.sizes?.[ imageDefaultSize ]
) {
mediaAttributes.sizeSlug = imageDefaultSize;
mediaAttributes.url = newMedia?.sizes?.[ sizeSlug ]?.url;
mediaAttributes.url =
newMedia?.sizes?.[ imageDefaultSize ]?.url ||
newMedia?.media_details?.sizes?.[ imageDefaultSize ]
?.source_url;
} else {
mediaAttributes.sizeSlug = DEFAULT_MEDIA_SIZE_SLUG;
}
Expand Down

0 comments on commit 7ff7679

Please sign in to comment.