I'm developing a plugin that adds a new tab to the media modal, and I need to know a way trigger a refresh of the attachments tab so it shows newly added attachments. This is the code I'm using:
wp.media.view.Toolbar.Custom = wp.media.view.Toolbar.extend({
initialize: function() {
_.defaults( this.options, {
event: 'custom_event',
close: false,
items: {
custom_event: {
text: wp.media.view.l10n.customButton,
style: 'primary',
priority: 80,
requires: false,
click: this.addAttachment
}
}
});
wp.media.view.Toolbar.prototype.initialize.apply( this, arguments );
},
// triggered when the button is clicked
addAttachment: function(){
this.controller.state().addAttachment();
this.controller.setState( 'insert' );
// I NEED TO TRIGGER A REFRESH OF THE ATTACHMENTS TAB HERE
}
});
Any help would be appreciated. The media modal documentation is almost non-existant.
Thanks
this.controller.state().addAttachment()
function is just an AJAX call usingwp.media.post()
, so I'd need to trigger an hypothetical "model updated" event somewhere after this AJAX call. Any ideas?