Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo of WP media uploader in metabox
jQuery(function($) {
var element_clicked = false;
$('#my-button').click(function() {
formfield = jQuery('#my-button').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
element_clicked = true;
return false;
});
// Store original function
window.original_send_to_editor = window.send_to_editor;
/**
* Override send_to_editor function from original script
* Writes URL into the textbox.
*
* Note: If header is not clicked, we use the original function.
*/
window.send_to_editor = function(html) {
if (element_clicked) {
imgurl = $('img',html).attr('src');
// do stuff here with the URL
element_clicked = false;
tb_remove();
} else {
window.original_send_to_editor(html);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.