0

I write a WordPress plugin that is adding a custom tab in the Media Library.

Problem is that sometimes when I open wp.media.frame content from custom tab is displayed inside of Media Library tab.

Like this:

enter image description here

My Code

var frame = wp.media.view.MediaFrame.Post;
wp.media.view.MediaFrame.Post = frame.extend({
    initialize: function() {
        frame.prototype.initialize.apply(this, arguments);

        var State = wp.media.controller.State.extend({
            insert: function() {
                console.log("Bla");
                this.frame.close();
            }
        })

        this.states.add([
            new State({
                id: 'custom',
                search: false,
                title: 'Custom'
            })
        ]);

        this.on('content:render:custom', this.renderUnsplashTabContent, this);
    },

    browseRouter: function(routerView) {
        routerView.set({
            upload: {
                text:     wp.media.view.l10n.uploadFilesTitle,
                priority: 20
            },
            custom: {
                text: wp.media.view.l10n.customTitle,
                priority: 30
            },
            browse: {
                text:     wp.media.view.l10n.mediaLibraryTitle,
                priority: 40
            },
        });
    },

    renderCustomTabContent: function() {
        var CustomView = wp.Backbone.View.extend({
            tagName: 'div',
            className: 'custom',
            template: wp.template('custom')
        })

        var view = new CustomView({
            data: data.frogs,
        });

        this.content.set(view);
    },
});

Did anyone got this problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.