Adding image upload functionality to a widget
-
Hi, I am trying to add the ability for users to upload an image in my widget options but the media upload box won’t open when the button is clicked. Here is my javascript code:
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(); } });
Here is my function loading the necessary scripts:
function my_admin_scripts() { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_register_script('my-upload', WP_PLUGIN_URL.'/WP-Simple-Social/wp-simple-social-image.js', array('jquery','media-upload','thickbox')); wp_enqueue_script('my-upload'); } function my_admin_styles() { wp_enqueue_style('thickbox'); } add_action('admin_print_scripts', 'my_admin_scripts'); add_action('admin_print_styles', 'my_admin_styles');
And here is my input field and upload button:
<input id="upload_image" class="widefat" type="text" size="36" name="upload_image" value="<?php echo esc_url( $image ); ?>" /> <input id="upload_image_button" type="button" value="Upload Image" />
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Adding image upload functionality to a widget’ is closed to new replies.