voceconnect / multi-post-thumbnails

Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
143 stars 63 forks source link

Fix attachment selection bug #58

Open DaveLMSP opened 9 years ago

DaveLMSP commented 9 years ago

I've been using Multiple Post Thumbnails v1.6.5 on a project involving a large media library (1500+ attachments) and have run into a bug where the details frequently fail to populate for a selected attachment when opening the MediaModal. After investigating, I determined that this occurs because a selected attachment is added to the frame's selection, but not explicitly fetched. If the selected attachment is included in the initial query-attachments call(s), details populate. If the attachment is not included, details remain blank until the attachment is loaded via a subsequent call.

This fix takes inspiration from the WordPress featured image uploader by explicitly fetching the selected attachment and then modifying the library's comparator so that a selected attachment shows before any other attachments. I also removed some redundant event handling by specifying multiple: false on frame creation and by adding a selected attachment only on frame open instead of open / activate.