首页 > 解决方案 > 将 wp 评论显示为拒绝所有用户

问题描述

我希望能够在 wp 的后端“拒绝”评论而不更改或删除评论内容。

在网站的前端,我希望将评论作者姓名列为正常,但评论内容中只有一个简单的声明,上面写着“此评论因违反我们的 TOS 而被拒绝”

我该怎么办?我发现似乎没有插件可以处理此功能。

标签: wordpresscomments

解决方案


您可以使用下面的代码片段。此代码段将过滤要显示的评论文本。

function filter_text( $comment_text, $comment = null ) {
    // Do something to the comment, possibly switching based on the presence of $comment
    $comment_text = 'This comment was rejected for violations of our TOS';
    return $comment_text;
}
add_filter( 'comment_text', 'filter_text', 10, 2 );

推荐阅读