How can I use Multi Media Uploader in the WordPress Plugins?

前端 未结 5 1778
死守一世寂寞
死守一世寂寞 2020-12-09 14:17

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.

                          


        
5条回答
  •  孤城傲影
    2020-12-09 14:37

    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 this

    How it works

    Add upload_image_button class on each upload button on the basis of this class click function triggers to fetch the wordpress multimedia uploader , see i have used the prev() property to get the previous element to the clicked one formfieldID=jQuery(this).prev().attr("id"); and then i have assigned the image url returned by uploader to formfieldID

     
        
    
    
        
    
    
    

    Also make sure you have included the necessary JS and CSS files of the uploader for this you have to add an action

    
    

    Note: Also take care of one thing when you assign the uploader to you input fields the control of uploader now assigns to the fields so when ever uploader will be called it assigns the image url to your text field , so this is the problem when you triggers the uploader you are unable to insert the images in the content area of the post for this solution you have to store the previous control in some where and when you are done with uploader then reassign the control of uploader to the previous function which i have provided in my JS code see below how it works

     var oldFunc = window.send_to_editor;
                        window.send_to_editor = function(html) {
    
                        imgurl = jQuery('img', html).attr('src');
                        jQuery("#"+formfieldID).val(imgurl);
                         tb_remove();
                        window.send_to_editor = oldFunc;
                        }
    

    I have used this technique many times and it works perfect for me

    Hope it makes sense

提交回复
热议问题