Muhammed Imran Hussain

LAMP, LEMP, MEAN, Android Developer

(WordPress) How to handle multiple instance of “send_to_editor” js function

WordPress built-in media uploader is a great library for uploading media. We can create a upload popup instance for upload media or select media from media library by following way:

After upload done we can get the media URL clicking on “Insert into..” button which actually calls “send_to_editor” function that receives media link as argument. So we can write following code to set image URL in a textbox.

It normally works when you have only one instance like bellow:

send_to_editor_screenshot_1

But what will happen for following scenario where we have two or more custom field area that needs to upload media and insert it into the texfield or container specified?

send_to_editor_screenshot_2

The solution is, overwrite the send_to_editor function when link or button is click that open the popup and store the old function to restore it. Also write the send_to_editor callback function inside the click event so that it will call for specific click event and it is also possible to write different logic for different area.

Leave a Reply

Your email address will not be published. Required fields are marked *