Guest User

Multiple Instances of the WP Uploaded in Metaboxes

a guest
Feb 1st, 2011
416
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* my html markup looks like */
  2. <input id="upload_image" type="text" size="36" name="upload_image" value="" />
  3. <button class="upload_image_button" type="button"><?php _e('Upload Image');?></button>
  4. <br /><span>Enter an URL or upload an image for the banner.</span>
  5.  
  6. /*my script looks like */
  7.  
  8. jQuery(document).ready(function($) {
  9. var formfield;
  10. $('.upload_image_button').click(function() {
  11.     formfield = $(this).prev('input');
  12.     tb_show('', 'media-upload.php?type=image&TB_iframe=true');
  13.     return false;
  14. });
  15.  
  16. window.original_send_to_editor = window.send_to_editor;
  17. window.send_to_editor = function(html){
  18.     if (formfield) {
  19.         fileurl = $('img',html).attr('src');
  20.         formfield.val(fileurl);
  21.         tb_remove();
  22.         formfield = ''; //reset formfield to null
  23.     } else {
  24.         window.original_send_to_editor(html);
  25.     }
  26. };
  27.  
  28. }); //end doc-ready
RAW Paste Data