Code Lover
Code Lover

Reputation: 8348

Wordpress TIny editor and upload option conflict

I am using upload media option and Tiny editor in my theme option. Now when I am using below javascript

jQuery(document).ready(function() {
    jQuery('.st_upload_button').click(function() {
         targetfield = jQuery(this).prev('.upload-url');
         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(targetfield).val(imgurl);
         tb_remove();
    }
});

it is allowing to upload image and insert url from upload button (see image with input and black upload button)

enter image description here

but with above javascript Tiny editor allowing upload but stops to inserting image into the editor.

enter image description here

I cross checked by disabling javascript and than Tiny editor works fine. So I believe something wrong in javascript but can't understand what is wrong and how to solve.

Upvotes: 2

Views: 481

Answers (1)

ManuA
ManuA

Reputation: 61

There is no problem in the jquery, only some has to be made while registering your scripts here is an sample code

     function st_add_init() 

    {

   $screen = get_current_screen();
   $file_dir = get_template_directory_uri();
   wp_enqueue_style("stCss", $file_dir."/font/theme-options.css", false, "1.0",    "all"); 
   wp_enqueue_script("stScript", $file_dir."/js/theme-options.js", false, "1.0");                             wp_register_script('my-upload', get_bloginfo( 'stylesheet_directory' ) .'/js/my-script.js', array('jquery','media-upload','thickbox'));    
   if ($screen->id =='appearance_page_st-settings')   
        {
          wp_enqueue_script('thickbox');
          wp_enqueue_script('media-upload');
          wp_enqueue_script('my-upload');
          wp_enqueue_style('thickbox');

        }
   }
   add_action('admin_enqueue_scripts', 'st_add_init');

The get_current_screen(); function retrieves the id of your theme option page

'appearance_page_st-settings' is the id of my option page, yours will be different

if ($screen->id =='appearance_page_st-settings') the id will be matched to identify whether the page is theme option page,if true, the script will be registered, therefore avoiding any conflict with the admin script

Upvotes: 2

Related Questions