the sample is from Display Media Uploader in Own Plugin on WordPress 3.5:
<script type="text/javascript">
var file_frame;
jQuery('.button-secondary').live('click', function( event ){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: 'Select File',
button: {
text: jQuery( this ).data( 'uploader_button_text' )
},
multiple: false
}
);
file_frame.on('select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
jQuery('#IMGsrc').val(attachment.url);
});
file_frame.open();
});
The problem is about
file_frame.on('select', function() {...});
dont returns DYNAMIC html. I’ve tried code like this:
jQuery(document).on('select', file_frame, function() {...});
jQuery(document).on('select', file_frame.el, function() {...});
but not working…
The window.send_to_editor(html) is called for compatibility reasons even in the new uploader, but I don’t think that will work when called this way. You can use the attributes of the object that you selected, and create a link/image html.
I fought with what I think was a similar problem. Part of the trouble was that upon upload, the first attachment object is empty and causes an error.
Here is my code example that outputs HTML as I need it on my site:
// When images are selected, place IDs in hidden custom field and show thumbnails.
file_frame.on( ‘select’, function() {
Hope this helps!