From 672c443c0a2d6c2e0a6cb2200a841acd87bac28e Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Tue, 12 Mar 2024 10:54:56 +0200 Subject: [PATCH] Site Editor: Fix selected featured image when opening media library (#59769) Co-authored-by: ntsekouras Co-authored-by: youknowriad --- .../src/components/media-upload/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/media-utils/src/components/media-upload/index.js b/packages/media-utils/src/components/media-upload/index.js index c62f755a27fb53..732a9bcabd79fc 100644 --- a/packages/media-utils/src/components/media-upload/index.js +++ b/packages/media-utils/src/components/media-upload/index.js @@ -300,19 +300,28 @@ class MediaUpload extends Component { */ buildAndSetFeatureImageFrame() { const { wp } = window; + const { value: featuredImageId, multiple, allowedTypes } = this.props; const featuredImageFrame = getFeaturedImageMediaFrame(); - const attachments = getAttachmentsCollection( this.props.value ); + const attachments = getAttachmentsCollection( featuredImageId ); const selection = new wp.media.model.Selection( attachments.models, { props: attachments.props.toJSON(), } ); this.frame = new featuredImageFrame( { - mimeType: this.props.allowedTypes, + mimeType: allowedTypes, state: 'featured-image', - multiple: this.props.multiple, + multiple, selection, - editing: this.props.value ? true : false, + editing: featuredImageId, } ); wp.media.frame = this.frame; + // In order to select the current featured image when opening + // the media library we have to set the appropriate settings. + // Currently they are set in php for the post editor, but + // not for site editor. + wp.media.view.settings.post = { + ...wp.media.view.settings.post, + featuredImageId: featuredImageId || -1, + }; } componentWillUnmount() {