Trigger refresh for new media manager in 3.5

I’m trying to figure out how it’s possible to ‘refresh’ the media library in the new media dialogue in 3.5. I’m adding images from an external image library to the WordPress library (via a tab/iFrame combo in the media dialogue) which works ok, but I have to close and reopen the dialogue in order to show the newly added images (which have successfully been aded to the library).

I know there are wp.media.editor.open() and wp.media.editor.close() methods, but I can’t quite manage to find a sort() or refresh() (or whatever) in the source. Truth be told, the source code is pretty intense reading and console.log doesn’t seemingly help much with backbone.js. Any ideas?

4

The correct way of refreshing the content of the frame, as found in the WP core, is as below:

if(wp.media.frame.content.get()!==null){
   wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
   wp.media.frame.content.get().options.selection.reset();
}else{
   wp.media.frame.library.props.set({ignore: (+ new Date())});
}

You should always check of the content is available, else refresh the library.

Cheers!

Leave a Comment