Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There must be a solution for this. I am using this solution for chooosing images from media library. http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

THE PROBLEM:

I am using two meta boxes for custom post type “products”.

First consists of two metafields what is for adding two addition product pictures The second one is for creating a simple gallery for this product.

Each of them has their own tb_show and window.send_to_editor stuff.

The thing is that everything works fine when there are registered only one metabox – the first or the second. If there are registered both of them, the last registered via add_meta_box , brings the error in firebug “too much recursion” when pressing “Insert into post” button.

How to solve this?

This is very mission critical, to have two of the metaboxes in post, to add different type of images? Also, the default Insert image in to post should work.

Maybe someone has a class for this because I see, the problem is if there are two original_send_to_editor functions registered in one post page.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I think you're running into a problem people mentioned in the comments to that story. Someone else posted about it here:

http://www.theenglishguy.co.uk/2010/01/24/multiple-media-uploads-in-wordpress-functions-php/

Basically, the JavaScript from that site should be modified to be more like this:

jQuery(document).ready(function() {

  var formlabel = 0;
  var old_send_to_editor = window.send_to_editor;
  var old_tb_remove = window.tb_remove;

  jQuery('.upload_image_button').click(function(){
    formlabel = jQuery(this).parent();
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    return false;
  });

  window.tb_remove = function() {
    formlabel = 0;
    old_tb_remove();
  }

  window.send_to_editor = function(html) {
    if(formlabel){
      imgurl = jQuery('img',html).attr('src');
      formlabel.find('input[type="text"]').value(imgurl);
      tb_remove();
    } else {
      old_send_to_editor();
    }
  }
});

From there, all you need to do is make sure all the buttons have the class 'upload_image_button', and make sure the button is a sibling to its corresponding text box and there are no other upload forms in the same parent element.

share|improve this answer
    
You are my monster!! IT works! –  jam Jun 18 '11 at 18:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.