What to use instead of wp_kses() in user output

Let’s go and see what would core do.

In default-filters.php here is what content output passes through:

add_filter( 'the_content', 'wptexturize'        );
add_filter( 'the_content', 'convert_smilies'    );
add_filter( 'the_content', 'convert_chars'      );
add_filter( 'the_content', 'wpautop'            );
add_filter( 'the_content', 'shortcode_unautop'  );
add_filter( 'the_content', 'prepend_attachment' );

None of these are dedicated security/escaping functions really.

It is similar for comments, which come from random visitors altogether and not even semi-trusted site authors:

add_filter( 'comment_text', 'wptexturize'            );
add_filter( 'comment_text', 'convert_chars'          );
add_filter( 'comment_text', 'make_clickable',      9 );
add_filter( 'comment_text', 'force_balance_tags', 25 );
add_filter( 'comment_text', 'convert_smilies',    20 );
add_filter( 'comment_text', 'wpautop',            30 );

In a nutshell it is reasonably trustworthy, having been scrubbed on submissions and coming back from database.

Leave a Comment