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.
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.
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:
which can all be extended using :
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?