On my personal blog, I would like commentors to be able to post code using certain shortcodes (eg [html], [css], [js], [php]). I still want to strip tags for comments for security reasons, but allow them between those shortcodes. When I write a test comment, "[html]<p>sample code</p>[/html]" becomes "[html]<p>sample code</p>[/html]". To get around this, I came up with the following code but I cannot get it to work. Could someone tell me what I am doing wrong? Thanks!
function process_code_tags($comment)
{
$comment = preg_replace_callback('/(\[html\])(.*?)(\[\/html\])/imsu', create_function('$matches', 'return $matches[0].htmlspecialchars_decode($matches[1]).$matches[2];'), $comment);
return $comment;
}
//add_filter('preprocess_comment', 'process_code_tags');
add_filter('comment_text', 'process_code_tags', 9);