Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
wp.media listen to changes / sync when opening a media modal
(function($,wp){
var handle_attachment_change = function(attachment){
console.log(attachment);
}
var media_modal = wp.media({
multiple: 'add',
library: {type: 'image'},
button: {
text: 'Select image'
}
});
media_modal.on('attach', function(){
var library = update_slide_frame.state().get('library');
// listen to the change event on the library items
media_modal.listenTo(library, 'change', function(attachment)){
// do something with the changed model
handle_attachment_change(attachment);
};
// listen to the Sync event on the library
media_modal.listenTo(library, 'sync', function(attachment)){
// do something with the changed model
handle_attachment_change(attachment);
};
});
})(jquery, wp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment