Getting a JS callback from the new WordPress Media Uploader

Is there a way to listen for an event when a user chooses an image from the WordPress Media Library/Uploader?

I’m developing an extension for a WordPress framework (Layers), which uses it’s own controls for uploading images and I don’t trigger the Uploader manually, which means I can’t hook up to it’s callback.

Read More

Is there a way to get the “global” media uploader, or the one that’s currently open?

Something like:

wp.media().on('insert', function(url) {
    console.log('isnerted image: ' + url);
});

I could not find anything in the WordPress Codex besides this example: http://codex.wordpress.org/Javascript_Reference/wp.media
Which assumes that I’m launching the editor myself.

Related posts

Leave a Reply

1 comment

  1. Too late for an assist? I’ve been looking at the same problem, thought I’d add a thought: The wp media-uploader js is here – https://github.com/WordPress/WordPress/blob/master/wp-includes/js/plupload/wp-plupload.js and looking at this problem https://wordpress.stackexchange.com/questions/92415/image-upload-callback-in-new-3-5-media I see there’s a method to extend callbacks from it. After looking at the uploader js I see the following:

    init:     function() {},
    error:    function() {},
    success:  function() {},
    added:    function() {},
    progress: function() {},
    complete: function() {}
    

    which can all be extended using :

    $.extend( wp.Uploader.prototype, {
        success : function(){
            console.log( 'callback action replacing this line' );
        }
    });
    

    replacing success with one of the six options above (in your case I’m thinking ‘insert’ becomes either ‘added’, or ‘complete’) don’t knw if that helps?