I’m currently using some JS to pop open the WordPress Media Library in a thickbox container and return the URL of a selected image, then display it.
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#upload_image-' + id_to_pass).val(imgurl);
output_code = '<img class="media_display" src="' + imgurl + '" />';
jQuery(output_code).appendTo('#media_display-' + id_to_pass);
tb_remove();
}
I was wondering if it’s possible to return the attachment ID instead?
I would like to use the image’s description and caption fields, which I won’t be able to do (easily) if I can only access the image URL from the Media Library.
Take a look at this http://sltaylor.co.uk/blog/hijacking-the-wordpress-media-library-overlay/
It’s more a hack than a solution. You could use a regex to extract the attachment ID from the
wp-image-
class. Add the following snippet to yourwindow.send_to_editor
function.