rest_after_insert_{$this->post_type}
云策文档标注
概述
rest_after_insert_{$this->post_type} 是一个动态 Hook,在通过 REST API 完全创建或更新单个文章后触发。它允许开发者在文章操作完成后执行自定义代码。
关键要点
- Hook 名称是动态的,基于文章类型 slug,例如 rest_after_insert_post、rest_after_insert_page。
- 触发时机:在 REST API 创建或更新文章操作完全完成后。
- 参数包括:WP_Post 对象、WP_REST_Request 对象和表示创建或更新的布尔值。
- 相关函数:WP_REST_Posts_Controller 和 WP_REST_Templates_Controller 中的 create_item() 和 update_item() 方法。
- 引入版本:WordPress 5.0.0。
原文内容
Fires after a single post is completely created or updated via the REST API.
Description
The dynamic portion of the hook name, $this->post_type, refers to the post type slug.
Possible hook names include:
rest_after_insert_postrest_after_insert_pagerest_after_insert_attachment
Parameters
$postWP_Post-
Inserted or updated post object.
$requestWP_REST_Request-
Request object.
$creatingbool-
True when creating a post, false when updating.
Source
do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |