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.

WP uses $allowedtags to limit the set of allowable tags for comments.However, comments from administrators are unfiltered.

What's the easiest way to ensure admin comments are also constrained to the tags contained in $allowedtags?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

kses_init is hooked onto the init hook with default priority, and (after first removing any of the kses filters) adds filters which strip out tags (wp_filter_post_kses for posts and wp_filter_kses for comments) if the user does not have the capability 'unfiltered_html'.

Since the capability determines whether or not the user can post 'unfiltered_html' comments and posts - you probably don't want to just remove that capability.

Instead, hook onto init, after kses_init, say with priority 20, and re-add the filters which strip out tags not in the $allowedtags whitelist:

add_action('init','wpse56687_filter_everyones_comments',20);
function wpse56687_filter_everyones_comments(){
      add_filter( 'pre_comment_content', 'wp_filter_kses' );
}
share|improve this answer
    
Great - thanks Stephen - that works exactly as needed. –  anu Jun 27 '12 at 14:09
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.