Refreshing collections in the admin media manager

I know this question is very similar to this previously asked question; however, I was wondering if there was a more up-to-date/official way to refresh content programmatically in the WordPress admin media manager.

In my specific instance, I’m trying to integrate the Getty Images plugin with a select attachment modal (e.g., Featured Image).

Currently, I’ve been able to successfully extend a few methods of media.view.MediaFrame.Select to integrate the plugin and select the attachments:

var media = wp.media;

var parentCoreSelect = media.view.MediaFrame.Select;

media.view.MediaFrame.Select = media.view.MediaFrame.Select.extend({

  // REFRESH CONTENT
  browseContent: function(){
    var state   = this.state()
      , library = state.get('library');

    /**** relevant part, adapted from other question ****/
    library.props.set({ '__ignore_force_update': (+ new Date()) });
    /**** relevant part, adapted from other question ****/

    parentCoreSelect.prototype.browseContent.apply(this, arguments);
  },

  // add getty plugin functionality to select attachment modal
  createStates: function(){
    parentCoreSelect.prototype.createStates.apply(this, arguments);
    this.states.add([
      // new getty controller -- omitted for brevity
    ]);
  }

});

This works to refresh the attachment content and I can see freshly downloaded images from Getty once I toggle back to Select an Image > Media Gallery. At this point, however, when I upload files via the Upload Files tab in the same modal, the upload occurs successfully but the attachment content in the Media Gallery is not updated (i.e., new upload is not visible to end user, although meta data is displayed in the right panel).

Is there a better way to do this so I can maintain the normal upload functionality, where the fresh upload is shown and selected?

Thanks!

0

Leave a Comment