钩子文档

rest_insert_comment

💡 云策文档标注

概述

rest_insert_comment 是一个 WordPress Hook,在通过 REST API 创建或更新评论后触发。它允许开发者在评论操作完成后执行自定义代码。

关键要点

  • 触发时机:在通过 REST API 成功创建或更新评论后立即执行。
  • 参数:接收三个参数:$comment(WP_Comment 对象,表示插入或更新的评论)、$request(WP_REST_Request 对象,表示请求数据)、$creating(布尔值,true 表示创建评论,false 表示更新评论)。
  • 用途:常用于扩展评论处理逻辑,如发送通知、记录日志或同步数据。
  • 相关函数:与 WP_REST_Comments_Controller 的 create_item() 和 update_item() 方法关联。
  • 版本历史:自 WordPress 4.7.0 版本引入。

📄 原文内容

Fires after a comment is created or updated via the REST API.

Parameters

$commentWP_Comment
Inserted or updated comment object.
$requestWP_REST_Request
Request object.
$creatingbool
True when creating a comment, false when updating.

Source

do_action( 'rest_insert_comment', $comment, $request, true );

Changelog

Version Description
4.7.0 Introduced.