window.send_to_editor throws unterminated string literal error when adding image with multi line description

I am using media-upload.php?type=image&tab=library script to add an image to a post with a description that contains html. This php script uses the javascript function window.send_to_editor to send the html to the page. This allows you to insert image html into a post.

The problem is, if you try to add an image with a description that has text broken up on multiple lines(html) you will get a unterminated string literal error from javascript b/c the string is not converted correctly before it is used.

Read More

Is there anyway around this?

Related posts

Leave a Reply

1 comment

  1. From comments:

    You have to use the image_send_to_editor filter to filter the string before it arrives at the window.send_to_editor javascript function.

    add_filter('image_send_to_editor', 'my_image_send_to_editor', 10, 2); 
    function my_image_send_to_editor($html, $id) 
    { 
        $description = str_replace("rn",' ', $description); 
    }