A-A+

wordpress过虑评论内容中的html代码

2015年01月02日 PHP开源系统 暂无评论 阅读 23 views 次

在最原始的 wordpress 评论页面是支持 html 标签的,虽然功能变得强大了,但其缺点也是明显的,你会收到一大堆的 html 的垃圾评论,尤其在 wordpress 的后台,里面又掺杂了韩语,日语,英语等,看着极不舒服,如果遇到这种情况的话,我们就需要将其屏蔽掉,虽然说不能彻底屏蔽掉 wordpress 的垃圾评论内容,但至少没有了 html 类的评论了。也就是将其过滤掉了,在其主题的 functions.php 文件下面加入如下的方法即可:

function plc_comment_post( $incoming_comment ) {
  
  
        $incoming_comment['comment_content'] = htmlspecialchar
s($incoming_comment['comment_content']);
  
        $incoming_comment['comment_content'] = str_replac
e( "'", ''', $incoming_comment['comment_content'] );
  
        return( $incoming_comment );
}
  
function plc_comment_display( $comment_to_display ) {
  
        $comment_to_display = str_replace( ''', "'", $co
mment_to_display );
  
        return $comment_to_display;
}
  
add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

实际上在一些 wordpress 主题中都集成了这个功能,我们在制作主题的时候也可以进行参考。

标签:

给我留言