Adding upload functionality to plugin
Let's say you have found yourself a great Wordpress plugin, but the only thing that is missing is a way to easily upload and or pick images or other file formats. Well you start Googling to see what is already out there. I my case I stumbled upon a great article in Webmaster Source. In this article they explain how you can a/ load the needed scripts to work with a Wordpress media uploader and b/ how to add the html needed to invoke the media uploader and a way to designate a field to store the url to the image or filetype of your choice.
HTML
Let's start with the code needed to load the necessary HTML:
I did remove the class thickbox here as it added to thickboxes in the same iframe.
PHP
And now the code to load the javascripts jQuery, ThickBox and our own custom javascript as well as the CSS we might like to add to style the media upload box we want to invoke when the upload image buttons is clicked:
I needed to add the name off my plugin after the constant in the path to load it all properly and to get the media upload window to load. One thing worth mentioning here is that you need to add this code snippet somewhere at the top of the plugin code. Otherwise the box won't pop-up.
Custom JavaScript
Here is the custom javascript that has to be loaded to open media-upload.php inside thickbox, fetch the url and put it in the proper text area:
I adjusted #upload_image in the script and used the id of the text area I wanted it to appear in:
| < Prev | Next > |
|---|


