过去几个小时我一直在研究,试图找到一种在 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 呢?