rest_insert_{$this->taxonomy}
云策文档标注
概述
rest_insert_{$this->taxonomy} 是一个 WordPress 动态 Hook,在通过 REST API 创建或更新单个分类法术语后触发。它允许开发者在术语操作完成后执行自定义代码。
关键要点
- 这是一个动态 Hook,名称中的 $this->taxonomy 部分会根据分类法 slug 动态替换,例如 rest_insert_category 或 rest_insert_post_tag。
- Hook 在术语创建或更新后触发,提供 $term(WP_Term 对象)、$request(WP_REST_Request 对象)和 $creating(布尔值,创建时为 true,更新时为 false)三个参数。
- 主要用于扩展 REST API 功能,例如在 WP_REST_Terms_Controller 和 WP_REST_Menus_Controller 中处理术语的创建和更新操作。
- 自 WordPress 4.7.0 版本引入。
原文内容
Fires after a single term is created or updated via the REST API.
Description
The dynamic portion of the hook name, $this->taxonomy, refers to the taxonomy slug.
Possible hook names include:
rest_insert_categoryrest_insert_post_tag
Parameters
$termWP_Term-
Inserted or updated term object.
$requestWP_REST_Request-
Request object.
$creatingbool-
True when creating a term, false when updating.
Source
do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |