1

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.

Is there anyway around this?

2
  • 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("\r\n",' ', $description); }
    – mike
    Apr 19 '11 at 17:46
  • Can you post your answer as an answer and mark it as accepted?
    – Jared
    Feb 3 '12 at 2:46
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("\r\n",' ', $description); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.