函数文档

wp_throttle_comment_flood()

💡 云策文档标注

概述

wp_throttle_comment_flood() 是一个 WordPress 核心函数,用于基于时间间隔判断评论是否因评论洪水(flood)而被阻止。它检查新评论与上次评论的时间差,若小于阈值则返回 true 以阻止评论。

关键要点

  • 函数接受三个参数:$block(布尔值,表示插件是否已阻止评论)、$time_lastcomment(上次评论的时间戳)、$time_newcomment(新评论的时间戳)。
  • 返回布尔值,指示评论是否应被阻止。
  • 如果 $block 为 true,函数直接返回 $block,尊重插件的阻止决定。
  • 通过计算时间差并与阈值比较来判定评论洪水。

代码示例

function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) {
    if ( $block ) { // A plugin has already blocked... we'll let that decision stand.
        return $block;
    }
    if ( ( $time_newcomment - $time_lastcomment ) < 15 ) { // 示例阈值,实际可能不同
        return true;
    }
    return false;
}

注意事项

  • 函数在 WordPress 2.1.0 版本中引入。
  • 开发者应确保时间戳参数正确传递,以避免误判。
  • 阈值可能因 WordPress 版本或配置而异,需参考最新文档。

📄 原文内容

Determines whether a comment should be blocked because of comment flood.

Parameters

$blockboolrequired
Whether plugin has already blocked comment.
$time_lastcommentintrequired
Timestamp for last comment.
$time_newcommentintrequired
Timestamp for new comment.

Return

bool Whether comment should be blocked.

Source

function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) {
	if ( $block ) { // A plugin has already blocked... we'll let that decision stand.
		return $block;
	}
	if ( ( $time_newcomment - $time_lastcomment ) < 15 ) {
		return true;
	}
	return false;
}

Changelog

Version Description
2.1.0 Introduced.