How to let a user select a media from the media library

Similar question can be found here and here. I use the following method, adapted from here: When your theme/plugin initializes: wp_enqueue_media(); Handle the media dialog in Javascript: var wp_media_dialog_field; function selectMedia() { var custom_uploader; if (custom_uploader) { custom_uploader.open(); return; } custom_uploader = wp.media.frames.file_frame = wp.media({ title: ‘Choose Image’, button: { text: ‘Choose Image’ }, multiple: … Read more

Using the WordPress 3.5 Media Uploader window as a modal popup

You can try the following script: var MEDIAmedia_library: function() { var formfield = null; var wireframe; $(‘body’).on(‘click’, ‘#click-event-selector’,function(e) { e.preventDefault(); if (wireframe) { wireframe.open(); return; } wireframe = wp.media.frames.wireframe = wp.media({ title: ‘Media Library Title’, button: { text: ‘Media Library Button Title’ }, multiple: false }); wireframe.on(‘select’, function() { attachment = wireframe.state().get(‘selection’).first().toJSON(); console.log(attachment); $(‘#input-field-selector’).val(attachment.url); }); … Read more