
























很久没看评论下的「回收站」,今天发现里面好多骂人的评论,全被系统自动标记成垃圾评论了,垃圾人写垃圾评论,很押韵,索性设置了下眼不见心不烦,命中恶意评论插件的评论会直接删除到垃圾桶,然后后台屏蔽垃圾桶和回收站,只留下待审核和通过审核的评论,这样连看都直接不用看了,也确实能做到「去你妈的恶评,老子看都不看」的境界。
我都懒得写小文章骂他们了,内容也就还是那几句,非要被我骂才能爽到,可以直接看这里
放下代码,需要的拿去吧:
// 隐藏评论页面中的“垃圾评论(Spam)”和“回收站(Trash)”标签
add_filter('views_edit-comments', 'hide_comments_spam_and_trash');
function hide_comments_spam_and_trash($views) {
// 移除垃圾评论
if (isset($views['spam'])) {
unset($views['spam']);
}
// 移除回收站
if (isset($views['trash'])) {
unset($views['trash']);
}
return $views;
}
/**
* 黑名单拦截增强版:
* - 之前已有审核通过评论的老用户 → 完全不受黑名单限制(正常提交)
* - 新用户(从未通过评论) → 命中关键字时弹出提示并跳转
*/
function custom_disallowed_comment_popup_redirect($commentdata) {
// 获取后台设置的禁止关键字
$disallowed = get_option('disallowed_keys');
if (empty($disallowed)) {
return $commentdata;
}
$keywords = explode("\n", $disallowed);
$keywords = array_map('trim', $keywords);
$keywords = array_filter($keywords);
if (empty($keywords)) {
return $commentdata;
}
$content = strtolower(trim($commentdata['comment_content']));
$author_email = isset($commentdata['comment_author_email']) ? strtolower(trim($commentdata['comment_author_email'])) : '';
// ==================== 判断是否为老评论者(有通过记录) ====================
$is_veteran = false;
if (!empty($author_email)) {
$args = array(
'author_email' => $author_email,
'status' => 'approve',
'number' => 1,
'fields' => 'ids',
'no_found_rows' => true, // 提升性能
);
$approved_comments = get_comments($args);
if (!empty($approved_comments)) {
$is_veteran = true;
}
}
// 如果是老用户(已有通过评论),直接放行,不做任何黑名单检查
if ($is_veteran) {
return $commentdata;
}
// ==================== 新用户:执行黑名单检查 ====================
foreach ($keywords as $keyword) {
if (empty($keyword)) {
continue;
}
if (strpos($content, strtolower(trim($keyword))) !== false) {
$alert_message = '你提交的文字命中系统黑名单,所有恶言诅咒会加倍返还给你,不用谢~'
. '\n\n如确认自己没说错话,或许是系统错误拦截,请酌情修改后重新提交!';
$redirect_url = home_url('/2796.htm');
wp_die(
'<script>
alert("' . esc_js($alert_message) . '");
window.location.href = "' . esc_js($redirect_url) . '";
</script>',
'评论提交失败',
array(
'response' => 200,
'back_link' => false
)
);
}
}
return $commentdata;
}
add_filter('preprocess_comment', 'custom_disallowed_comment_popup_redirect', 1, 1);
操作步骤:
这个代码只影响界面显示,不会真正禁用 Spam 或 Trash 功能:
之前全站关闭VPN外网访问了一段时间,确实清净了,后来因为自己偶尔挂着VPN导致还得关了才能看自己博客就又开了,结果吧,有些狗东西就会开着VPN来留言找存在感,考虑是不是应该直接全站关闭评论了。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。