8

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

  • IIRC those are just Backbone/Underscore views. In other words, when you update the model, it should update the view by itself as the "ModelView" should trigger that. – kaiser Feb 25 '15 at 10:01
  • Well, the this.controller.state().addAttachment() function is just an AJAX call using wp.media.post(), so I'd need to trigger an hypothetical "model updated" event somewhere after this AJAX call. Any ideas? – leemon Feb 25 '15 at 10:49
  • "Any ideas?" - currently, no. This is something where I'd have to invest quite some time to read through core (which I don't have now). About your comment: There's MarkDown available (See "help" below "add comment" button). – kaiser Feb 25 '15 at 11:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.