WP 3.5 Media Uploader Code for multiple uploaders
-
I’m looking to tweak the following JS to work with any instance of an image uploader and have exhausted every idea I can come up with. I can make it work with specific element IDs but that requires duplicated code.
this is what I think needs to be tweaked.
$(field).val(attachment.url);
I’ve messed with closest(), next(), prev() pretty much anything I could think of with JQuery.jQuery(document).ready(function($){ var custom_uploader; $("input[id^='upload_image_button']").click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen the dialog if (custom_uploader) { custom_uploader.open(); return; } var myClass = $(this).attr("class"); var field = "#upload_image_"+myClass; alert(myClass); //Extend the wp.media object custom_uploader = wp.media.frames.file_frame = wp.media({ title: 'Choose Image', button: { text: 'Choose Image' }, multiple: false }); //When a file is selected, grab the URL and set it as the text field's value custom_uploader.on('select', function() { attachment = custom_uploader.state().get('selection').first().toJSON(); $(field).val(attachment.url); }); //Open the uploader dialog custom_uploader.open(); }); });
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘WP 3.5 Media Uploader Code for multiple uploaders’ is closed to new replies.