I try to add the multi uploading options in the wordpress plugins I repeated this code in the plugin(two times) only changing the id name.
<script language="JavaScript">
jQuery(document).ready(function($) {
jQuery('#upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img', html).attr('src');
jQuery('#upload_image').val(imgurl);
tb_remove();
};
});
</script>
<input id="upload_image" style=" margin-left:303px;" type="text" size="36" name="upload_image_template" value="<?php echo get_option('upload_image_template'); ?>" />
<input id="upload_image_button" type="button" value="Browse" />
Whenever I try to upload a image that media frame comes and the uploading process are did successfully. But Insert Into Post fetch the correct url but pasted in different input box. For example:
1) [text box1] [browse Button]
2) [text box2] [browse button]
When I upload image with Text Box One that [insert post]
that image path is shown in [text box 2]
I am Not Sure Whether the Problem is mine or that script didn't support multi file upload option.
Here is my code based on Codex wp.media Example
Javascript
HTML
Tip
if you console.log frame,you will be exposed to API :)
It wasn't that hard...
See this revision history to see how I did... Basically what I did was adding this to my plugin:
You can just copy and paste this code to your plugin and see the magic.
Here, for the edit image to work, also to show other filter, hope it helps.
Here is the example how you can use the wordpress multimedia uploader for more than one field or as many fields. The
JS
code and html code looks like thisHow it works
Add
upload_image_button
class on each upload button on the basis of this classclick
function triggers to fetch the wordpress multimedia uploader , see i have used theprev()
property to get the previous element to the clicked oneformfieldID=jQuery(this).prev().attr("id");
and then i have assigned the image url returned by uploader toformfieldID
Also make sure you have included the necessary
JS
andCSS
files of the uploader for this you have to add an actionI have used this technique many times and it works perfect for me
Hope it makes sense
The answer from M Khalid Junaid is great but outdated.
See the codex page about wp.media : https://codex.wordpress.org/Javascript_Reference/wp.media.