How to trigger a refresh in the media modal

by leemon   Last Updated May 27, 2019 13:08 PM

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



Related Questions



Open the attachment details modal

Updated May 28, 2015 22:03 PM

add attachment-filters on custom modal media insert

Updated March 20, 2016 08:03 AM


Use wordpress media selector in tinymce popup

Updated February 18, 2017 21:08 PM