Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer 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); 
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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