Skip to content

Commit

Permalink
Site Editor: Fix selected featured image when opening media library (#…
Browse files Browse the repository at this point in the history
…59769)

Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent deac5e8 commit 672c443
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/media-utils/src/components/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 672c443

Please sign in to comment.