WordPress转换评论中的HTML实体

// escape html entities in comments
function encode_code_in_comment($source) {
    $encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims',
            create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
        return "<code>" . htmlentities($matches[1]) . "</"."code>";'), $source);
    if ($encoded)
                return $encoded; else
                return $source;
}
add_filter('pre_comment_content', 'encode_code_in_comment');

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据