钩子文档

term_id_filter

💡 云策文档标注

概述

本文档介绍 WordPress 中的 term_id_filter Hook,它在创建新术语后过滤术语 ID。此 Hook 允许开发者在术语插入过程中修改或处理术语 ID。

关键要点

  • term_id_filter 是一个 WordPress Hook,在 wp_insert_term() 函数创建新术语后触发。
  • Hook 接收三个参数:$term_id(术语 ID)、$tt_id(术语分类法 ID)和 $args(传递给 wp_insert_term() 的参数数组)。
  • 从 WordPress 6.1.0 版本开始,添加了 $args 参数,增强了 Hook 的功能性。

代码示例

$term_id = apply_filters( 'term_id_filter', $term_id, $tt_id, $args );

注意事项

  • 此 Hook 主要用于在术语创建后自定义术语 ID 的处理逻辑,例如日志记录或数据验证。
  • 相关函数包括 wp_update_term() 和 wp_insert_term(),它们分别用于更新和插入术语。
  • Hook 自 WordPress 2.3.0 版本引入,在 6.1.0 版本中增加了 $args 参数,以提供更多上下文信息。

📄 原文内容

Filters the term ID after a new term is created.

Parameters

$term_idint
Term ID.
$tt_idint
Term taxonomy ID.
$argsarray
Arguments passed to wp_insert_term() .

More Arguments from wp_insert_term( … $args )

Array or query string of arguments for inserting a term.

  • alias_of string
    Slug of the term to make this term an alias of.
    Accepts a term slug.
  • description string
    The term description.
  • parent int
    The id of the parent term. Default 0.
  • slug string
    The term slug to use.

Source

$term_id = apply_filters( 'term_id_filter', $term_id, $tt_id, $args );

Changelog

Version Description
6.1.0 The $args parameter was added.
2.3.0 Introduced.