Use WordPress Media Uploader in your Custom Plugin

This will make is

Basicly what I did was adding this to my plugin:

function test_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('jquery');
}

function test_admin_styles() {
wp_enqueue_style('thickbox');
}

add_action('admin_print_scripts', 'test_admin_scripts');
add_action('admin_print_styles', 'test_admin_styles');

And later this part:

<script language="JavaScript">
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;
});

window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#upload_image').val(imgurl);
tb_remove();
}

});
</script>

<tr valign="top">
	<td>Upload Image</td>
	<td><label for="upload_image">
		<input id="upload_image" type="text" size="36" name="upload_image" value="<?php echo $yourimage; ?>" />
		<input id="upload_image_button" type="button" value="Upload Image" />
		<br />Enter an URL or upload an image for the banner.
		</label>
	</td>
</tr>

Leave a Reply