From 7ff76796b8fd7027a3f53933e1f9e5f2917ea2c8 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 6 Nov 2024 09:44:02 +0400 Subject: [PATCH] Cover: Fix media library image selection (#66782) * Cover: Fix media library image selection * Fix sizes for uploaded images Co-authored-by: Mamaduka Co-authored-by: aaronrobertshaw Co-authored-by: richtabor --- .../block-library/src/cover/edit/index.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/cover/edit/index.js b/packages/block-library/src/cover/edit/index.js index 0ad87601bfba8b..1202f28cee50cd 100644 --- a/packages/block-library/src/cover/edit/index.js +++ b/packages/block-library/src/cover/edit/index.js @@ -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; }