钩子文档

spam_comment

💡 云策文档标注

概述

spam_comment 是一个 WordPress 动作钩子,在评论被标记为垃圾之前立即触发。它允许开发者在评论被标记为垃圾时执行自定义操作。

关键要点

  • spam_comment 钩子在评论被标记为垃圾前触发,提供 $comment_id 和 $comment 参数。
  • 参数包括 $comment_id(评论 ID)和 $comment(WP_Comment 对象)。
  • 从 WordPress 4.9.0 版本开始添加了 $comment 参数,增强了钩子的功能。

代码示例

do_action( 'spam_comment', $comment->comment_ID, $comment );

注意事项

  • 此钩子与 wp_spam_comment() 函数相关,该函数用于将评论标记为垃圾。
  • 钩子自 WordPress 2.9.0 版本引入,4.9.0 版本增加了 $comment 参数。

📄 原文内容

Fires immediately before a comment is marked as Spam.

Parameters

$comment_idint
The comment ID.
$commentWP_Comment
The comment to be marked as spam.

Source

do_action( 'spam_comment', $comment->comment_ID, $comment );

Changelog

Version Description
4.9.0 Added the $comment parameter.
2.9.0 Introduced.