钩子文档

delete_comment

💡 云策文档标注

概述

delete_comment 是一个 WordPress 动作钩子,在评论从数据库删除前立即触发。它允许开发者在删除操作执行前执行自定义代码。

关键要点

  • 触发时机:评论从数据库删除前立即触发。
  • 参数:$comment_id(评论 ID 作为数字字符串)和 $comment(要删除的 WP_Comment 对象)。
  • 版本历史:从 WordPress 1.2.0 引入,4.9.0 版本添加了 $comment 参数。
  • 相关函数:与 wp_delete_comment() 函数关联,用于处理评论的删除或移至回收站。

📄 原文内容

Fires immediately before a comment is deleted from the database.

Parameters

$comment_idstring
The comment ID as a numeric string.
$commentWP_Comment
The comment to be deleted.

Source

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

Changelog

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