钩子文档

wp_is_comment_flood

💡 云策文档标注

概述

wp_is_comment_flood 是一个 WordPress 过滤器,用于判断评论是否属于评论洪水攻击的一部分。它允许开发者自定义评论洪水的检测逻辑,并控制处理方式。

关键要点

  • 过滤器名称:wp_is_comment_flood,用于过滤评论洪水状态。
  • 默认检测函数:wp_check_comment_flood(),基于 check_comment_flood_db() 实现。
  • 参数:包括 $is_flood(布尔值,默认 false)、$comment_author_ip(IP 地址)、$comment_author_email(邮箱)、$comment_date_gmt(GMT 时间)、$wp_error(布尔值,控制是否返回 WP_Error 对象)以及 wp_die() 相关参数(如 response、link_url、link_text 等)。
  • 用途:在 wp_allow_comment() 中调用,验证评论是否允许发布。
  • 版本变更:5.5.0 版本将 $avoid_die 参数重命名为 $wp_error;4.7.0 版本引入。

代码示例

$is_flood = apply_filters(
    'wp_is_comment_flood',
    false,
    $commentdata['comment_author_IP'],
    $commentdata['comment_author_email'],
    $commentdata['comment_date_gmt'],
    $wp_error
);

📄 原文内容

Filters whether a comment is part of a comment flood.

Description

The default check is wp_check_comment_flood() . See check_comment_flood_db() .

Parameters

$is_floodbool
Is a comment flooding occurring? Default false.
$comment_author_ipstring
Comment author’s IP address.
$comment_author_emailstring
Comment author’s email.
$comment_date_gmtstring
GMT date the comment was posted.
$wp_errorbool
Whether to return a WP_Error object instead of executing wp_die() or die() if a comment flood is occurring.

More Arguments from wp_die( … $args )

Arguments to control behavior. If $args is an integer, then it is treated as the response code.

  • response int
    The HTTP response code. Default 200 for Ajax requests, 500 otherwise.
  • link_url string
    A URL to include a link to. Only works in combination with $link_text.
  • link_text string
    A label for the link to include. Only works in combination with $link_url.
  • back_link bool
    Whether to include a link to go back. Default false.
  • text_direction string
    The text direction. This is only useful internally, when WordPress is still loading and the site’s locale is not set up yet. Accepts 'rtl' and 'ltr'.
    Default is the value of is_rtl() .
  • charset string
    Character set of the HTML output. Default 'utf-8'.
  • code string
    Error code to use. Default is 'wp_die', or the main error code if $message is a WP_Error.
  • exit bool
    Whether to exit the process after completion. Default true.

Source

$is_flood = apply_filters(
	'wp_is_comment_flood',
	false,
	$commentdata['comment_author_IP'],
	$commentdata['comment_author_email'],
	$commentdata['comment_date_gmt'],
	$wp_error
);

Changelog

Version Description
5.5.0 The $avoid_die parameter was renamed to $wp_error.
4.7.0 Introduced.