comment_{$new_status}_{$comment->comment_type}
云策文档标注
概述
comment_{$new_status}_{$comment->comment_type} 是一个 WordPress 钩子,在特定评论类型的状态转换时触发。它允许开发者在评论状态变化时执行自定义操作。
关键要点
- 钩子名称是动态的,基于 $new_status(新评论状态)和 $comment->comment_type(评论类型)构建。
- 典型评论类型包括 'comment'、'pingback' 或 'trackback'。
- 可能的钩子名称示例:comment_approved_comment、comment_spam_pingback 等。
- 参数包括 $comment_id(评论 ID 作为数字字符串)和 $comment(WP_Comment 对象)。
- 由 wp_transition_comment_status() 函数调用,用于处理评论状态转换。
- 自 WordPress 2.7.0 版本引入。
代码示例
do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
原文内容
Fires when the status of a specific comment type is in transition.
Description
The dynamic portions of the hook name, $new_status, and $comment->comment_type, refer to the new comment status, and the type of comment, respectively.
Typical comment types include ‘comment’, ‘pingback’, or ‘trackback’.
Possible hook names include:
comment_approved_commentcomment_approved_pingbackcomment_approved_trackbackcomment_unapproved_commentcomment_unapproved_pingbackcomment_unapproved_trackbackcomment_spam_commentcomment_spam_pingbackcomment_spam_trackback
Parameters
$comment_idstring-
The comment ID as a numeric string.
$commentWP_Comment-
Comment object.
Source
do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |