5

Using jquery, I am trying to get image attachment id of all images requested to upload through media uploader on post edit page or upload.php. Here is what I tried but this works after all images are uploaded:

if (typeof wp.Uploader !== 'undefined' && typeof wp.Uploader.queue !== 'undefined') {
    wp.Uploader.queue.on('reset', function() { 
        console.log('images uploaded!');
    });
}

How can achieve the same? Thanks

1

You are close, you just need to hook into the add event instead of the reset event. (In case you did not know, these are standard events provided by Backbone collections. So familiarizing yourself with that will be helpful when developing things around stuff where WordPress employs Backbone.js.)

So basically you'd modify your code like this:

if (typeof wp.Uploader !== 'undefined' && typeof wp.Uploader.queue !== 'undefined') {
    wp.Uploader.queue.on('add', function() { 
        console.log('image uploaded!');
    });
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.