var workflow = wp.media({ title: 'Select the images', // use multiple: false to disable multiple selection multiple: 'add', button: { text: 'Add selected images' }, library: { type: 'image' } }); function getAttachment(attachment) { attachment = attachment.toJSON(); return {id:attachment.id,url:attachment.url}; } function select() { // use this to unbind the event // workflow.off("select"); // get all selected images (id/url attributes only) console.log(workflow.state().get('selection').map(getAttachment)); } function reset() { // called when dialog is closed by "close" button / "ESC" key // use the following line unbind the event // workflow.off("select"); } // bind event handlers workflow.on("select",select); workflow.on("escape",reset); // open the dialog workflow.open();