• Resolved Nalin

    (@nalin_duminda)


    I created Theme options for my WordPress Theme. And I manged create Image Uploader popup and managed successfully insert in to field also (image URL). here is script I use.

    jQuery('#brochure_button').click(function() {
    	formfield = jQuery(this).prev().attr('name');
    	tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    	return false;
    	});
    
    	window.send_to_editor = function(html) {
    	imgurl = jQuery(html).attr('href');
    	// I then called the name and joined with # for the id.
    	jQuery("#"+formfield).val(imgurl);
    	tb_remove();
    	}

    in function.php

    function my_admin_scripts() {
    		wp_enqueue_script('media-upload');
    		wp_enqueue_script('thickbox');
    		wp_register_script('my-upload', get_bloginfo('template_url').'/scripts/admin_scripts.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');

    but Now when I upload image to a post or page using normal Image Uploader I can’t insert the picture into content area of that post or page. I get the button but once I clicked it popup goes blank and it’s not closing even.

    Any idea how to fix this.

    Thanks,
    nalin

Viewing 1 replies (of 1 total)
  • Thread Starter Nalin

    (@nalin_duminda)

    Found the way… 😀

    jQuery(document).ready(function() {
    	var formfield;
    
    jQuery('#brochure_button').click(function() {
    	formfield = jQuery(this).prev().attr('name');
    	tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    	return false;
    	});
    
    window.original_send_to_editor = window.send_to_editor;
    	window.send_to_editor = function(html){
    
    		if (formfield) {
    			alert(formfield);
    			fileurl = jQuery(html).attr('href');
    
    			jQuery('#'+formfield).val(fileurl);
    
    			tb_remove();
    			formfield = '';
    
    		} else {
    			window.original_send_to_editor(html);
    		}
    	};
    });
Viewing 1 replies (of 1 total)
  • The topic ‘Can't insert picture into post with Image uploader’ is closed to new replies.