How To Integrate The WordPress Media Uploader Into Your Plugin
The following snippet will let you integrate the WordPress media uploader into your plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// PHP, adds the appropriate scripts and styles in admin add_action('admin_print_scripts',array(&$this,'uploader_scripts')); add_action('admin_print_styles',array(&$this,'uploader_styles')); public function uploader_scripts(){ wp_enqueue_script('media-upload'); wp_enqueue_script('thinkbox'); } public function uploader_styles(){ wp_enqueue_style('thickbox'); } // The html for the button and hidden input for result (super simple) <input id="backdrop_upload_button" value="Upload/Select Image" type="button" class="button" /> <input type="hidden" name="the_image" id="the_image" value="<?= $settings['the_image'] ?>" /> // The jQuery to open the media uploader and get the response var $ = jQuery; // Handels image uploading $(document).ready(function(){ $("input#upload_button").click(function(){ tb_show('','media-upload.php?type=image&post_id=1&TB_iframe=true&flash=0&backdrop=true'); return false; }) window.send_to_editor=function(html){ var img = $('<div>'+html+'</div>').find('img').attr('src'); $('#the_image').val(img); tb_remove(); }; }); |
Snippet Source/Credit: FatFolderDesign
How To No-Follow WordPress Tag Cloud
The following snippet will let