钩子文档

check_comment_flood

💡 云策文档标注

概述

check_comment_flood 是一个 WordPress 动作钩子,在评论被标记为批准前触发,主要用于检查评论洪水攻击。

关键要点

  • 触发时机:在评论被标记为批准之前立即执行。
  • 主要功能:允许开发者检查评论洪水,防止恶意或重复评论。
  • 参数:包括评论作者的 IP 地址、邮箱、GMT 发布时间、是否返回 WP_Error 对象等。
  • wp_die 参数:可传递额外参数控制错误处理行为,如 HTTP 响应码、链接等。
  • 源调用:通过 do_action 在 wp_allow_comment() 中触发。
  • 版本变更:从 5.5.0 起 $avoid_die 参数更名为 $wp_error,4.7.0 添加该参数,2.3.0 引入此钩子。

📄 原文内容

Fires immediately before a comment is marked approved.

Description

Allows checking for comment flooding.

Parameters

$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

do_action(
	'check_comment_flood',
	$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 The $avoid_die parameter was added.
2.3.0 Introduced.