惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
G
Google Developers Blog
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
爱范儿
爱范儿
B
Blog
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
博客园_首页
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence

N25H

Maye Nano:拒绝臃肿,回归纯粹的快速启动工具 – N25H Maye Nano Script Help – N25H 国行三星 Galaxy Watch7 其他品牌手机解锁心电图、血压等功能 – N25H 推翻重做,彻底重写WordPress主题 – N25H WordPress 模板目前采用的缓存获取方案 – N25H 相册测试1 – N25H 相册测试2 – N25H 从 Typecho 迁移到 WordPress 的后续 – N25H 在Linux Ubuntu上挂载新硬盘 (临时、永久挂载) – N25H
WordPress 通过Hook修改评论Flood判定时间 – N25H
作者: N25H · 2023-12-12 · via N25H

如果是使用wp原生评论系统直接通过钩子comment_flood_filter拦截即可

在主题function.php文件中加入以下代码:

if ( !function_exists( 'mz_comment_flood_filter' ) ){
    function mz_comment_flood_filter( $dam_it, $time_lastcomment, $time_newcomment ) {

        if( !is_admin() ) {
            if ( ( $time_newcomment - $time_lastcomment ) < MZ_COMMENT_FLOOD_TIME ) { // 间隔为10秒
                return true;
            }
            
            return false;
        }
        
    }
}
add_filter( 'comment_flood_filter', 'mz_comment_flood_filter', 10, 3 );

这个回调的大概意思是,不在后台的情况下,用当前发布的时间减去上次的时间,如果小于MZ_COMMENT_FLOOD_TIME则判定为Flood,否则什么都不做

为了方便快速控制判断时间,这里定义了一个MZ_COMMENT_FLOOD_TIME

define('MZ_COMMENT_FLOOD_TIME',     10);

ps:函数add_filter,的参数依次为:hook名,回调,优先级,参数数量


详情参考:comment_flood_filter

赞赏作者

如果觉得我的文章对你有用,请随意赞赏