钩子文档

rest_after_insert_{$this->taxonomy}

💡 云策文档标注

概述

rest_after_insert_{$this->taxonomy} 是一个 WordPress REST API 钩子,在通过 REST API 完全创建或更新单个分类法术语后触发。钩子名称的动态部分基于分类法 slug,允许针对特定分类法进行定制。

关键要点

  • 触发时机:在通过 REST API 成功创建或更新单个分类法术语后立即执行。
  • 动态钩子:钩子名称包含动态部分 {$this->taxonomy},例如 rest_after_insert_category 或 rest_after_insert_post_tag,具体取决于分类法。
  • 参数:接收三个参数:$term(WP_Term 对象,表示插入或更新的术语)、$request(WP_REST_Request 对象,包含请求数据)和 $creating(布尔值,创建时为 true,更新时为 false)。
  • 用途:常用于在术语创建或更新后执行自定义操作,如清理缓存、发送通知或同步数据。
  • 相关控制器:在 WP_REST_Menus_Controller 和 WP_REST_Terms_Controller 的 create_item() 和 update_item() 方法中使用。
  • 版本历史:自 WordPress 5.0.0 版本引入。

📄 原文内容

Fires after a single term is completely 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_after_insert_category
  • rest_after_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_after_insert_{$this->taxonomy}", $term, $request, true );

Changelog

Version Description
5.0.0 Introduced.