Latest code for image upload field using ThickBox in (DataFeedr) plugin:
<?php
// Add code for upload field
function my_admin_scripts() { // function to load scripts
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('my-upload', WP_PLUGIN_URL.'/datafeedr-ads/my-script.js', array('jquery','media-upload','thickbox'));
wp_enqueue_script('my-upload');
}
function my_admin_styles() {
wp_enqueue_style('thickbox');
}
if (isset($_GET['page']) && $_GET['page'] == 'datafeedr-ads') {
add_action('admin_print_scripts', 'my_admin_scripts'); // load own javascripts
add_action('admin_print_styles', 'my_admin_styles'); // load own css
}
?>
<tr valign="top">
<td><label for="upload_image">
<div class="clear" style="height:10px;"></div>
Enter an URL or upload an image for the ad. <br />
<input id="upload_image_button" type="button" value="Insert Image" />
</label></td>
</tr>
<div class="clear" style="height:10px;"></div>
<div>
<a href="javascript:;" onclick="addEvent();" class="button-secondary">Add Box</a>
<input name="submit-edit-group" type="submit" value="Save Changes" class="button-secondary">
<div class="clear"> </div>
Here the JavaScript (my-script.js):
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;
});
// send url back to plugin editor
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#dfrads_textarea').val(imgurl);
tb_remove();
}
});