• I want an image upload in my widget.
    The WP image upload screen pops up like it should but when i choose an image, the url is not returned to the textfield. Any idea why?

    php :

    // queue up the necessary js
    function hrw_enqueue()
    {
      wp_enqueue_style('thickbox');
      wp_enqueue_script('media-upload');
      wp_enqueue_script('thickbox');
      // moved the js to an external file, you may want to change the path
      wp_enqueue_script('hrw', plugin_dir_url( __FILE__ ).'js/uploadimg.js', null, null, true);
    }
    add_action('admin_enqueue_scripts', 'hrw_enqueue');
    

    html

    
     <p>
          <label for="<?php echo $this->get_field_id('image_uri'); ?>">Image</label><br />
          <input type="text" class="img" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $instance['image_uri']; ?>" />
          <input type="button" class="select-img" value="Select Image" />
        </p>
    

    js file :

    
    jQuery( document ).ready(function() {
    	var image_field;
    jQuery(function($){
      $(document).on('click', 'input.select-img', function(evt){
        image_field = $(this).siblings('.img');
        tb_show('', 'media-upload.php?type=image&TB_iframe=true');
        return false;
      });
      window.send_to_editor = function(html) {
        imgurl = $('img', html).attr('src');
        image_field.val(imgurl);
        tb_remove();
      }
    });
    
    });
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘WP image upload not returning URL’ is closed to new replies.