1

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?

1 Answer 1

1

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' );
}
1
  • Great - thanks Stephen - that works exactly as needed.
    – anu
    Jun 27, 2012 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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