禁用注释上的HTML

  • 本文关键字:HTML 注释 wordpress
  • 更新时间 :
  • 英文 :


我在过去的几个小时里一直在研究,试图找到一种在WordPress评论中禁用HTML的方法。到目前为止,这个一直多次出现在谷歌搜索结果的顶部:

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {
// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''',         $incoming_comment['comment_content'] );
return( $incoming_comment );
}
// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {
// Put the single quotes back in
$comment_to_display = str_replace( ''', "'", $comment_to_display );
return $comment_to_display;

此代码不适用于最新版本的WordPress。我还发现了更多的代码,这些代码再次不起作用。那么,如何禁用WordPress 3.6(最新版本)评论中的HTML呢?

这删除了用户在评论中发布HTML(但由于某些奇怪的原因,不能发布链接)的能力:

add_filter( 'pre_comment_content', 'wp_specialchars' );

这删除了用户在评论中发布链接的能力:

remove_filter('comment_text', 'make_clickable', 9);

要禁用注释中的HTML标记,请将以下代码放入主题的functions.php:

add_filter('comment_text', 'wp_filter_nohtml_kses');
add_filter('comment_text_rss', 'wp_filter_nohtml_kses');
add_filter('comment_excerpt', 'wp_filter_nohtml_kses');

最新更新