rest_insert_{$this->post_type}
云策文档标注
概述
rest_insert_{$this->post_type} 是一个 WordPress REST API 钩子,在通过 REST API 创建或更新单个文章后触发。钩子名称的动态部分 $this->post_type 指文章类型 slug。
关键要点
- 触发时机:在通过 REST API 创建或更新单个文章后执行。
- 钩子名称:动态钩子,例如 rest_insert_post、rest_insert_page、rest_insert_attachment。
- 参数:$post(WP_Post 对象,插入或更新的文章)、$request(WP_REST_Request 对象,请求数据)、$creating(布尔值,创建文章时为 true,更新时为 false)。
- 相关函数:由 WP_REST_Posts_Controller::create_item() 和 WP_REST_Posts_Controller::update_item() 使用。
- 版本历史:自 WordPress 4.7.0 引入。
原文内容
Fires after a single post is 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_insert_postrest_insert_pagerest_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_insert_{$this->post_type}", $post, $request, true );
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |