Timo Haapala
Timo Haapala

Reputation: 87

wp_update_comment() loses html-tags

I've done a customized comment form for a Wordpress website and there is a possibility for users to add comments. I managed to allow more html-tags to these comments than the default ones. The tags work just fine when a new comment is posted, but when the comment is updated it loses all of these additionally allowed tags.

For updating the comment, I'm using wp_update_comment() -method. I searched a bit, but didn't find a solution yet. I'm passing comment's ID and comment's content as arguments for the method.

So what I'm basically asking is, can I use this method to accomplish what I'm trying to do? Or should I delete the comment and create a new one in it's place?

Upvotes: 0

Views: 244

Answers (2)

ale8oneboy
ale8oneboy

Reputation: 127

Looking at the source for wp_update_comment() it looks like it cleans the comment up before updating the database. You may have to write your own function for this to get around it.

Upvotes: 0

Felipe Elia
Felipe Elia

Reputation: 1418

That happens because wp_update_comment() calls wp_filter_comment function, and that one filters the content using the pre_comment_content filter. WP plugs the wp_filter_kses function to this filter, so using

remove_filter('pre_comment_content', 'wp_filter_kses');

before calling wp_update_comment() should solve your problem. Just remember that you do have to filter the sent comment somehow to avoid security problems, ok?

Upvotes: 1

Related Questions