Skip to content

Instantly share code, notes, and snippets.

@bitfade
Last active April 3, 2017 07:58
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bitfade/4460948 to your computer and use it in GitHub Desktop.
WordPress 3.5 media upload api example
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment