钩子文档

pre_insert_term

💡 云策文档标注

概述

pre_insert_term 是一个 WordPress 过滤器,用于在术语被清理并插入数据库之前进行过滤。它允许开发者在术语插入过程中修改术语名称或处理错误。

关键要点

  • 过滤器钩子名称为 'pre_insert_term',在 wp_insert_term() 函数中被调用。
  • 参数包括 $term(术语名称或 WP_Error 对象)、$taxonomy(分类法 slug)和 $args(传递给 wp_insert_term() 的参数数组或字符串)。
  • 从 WordPress 6.1.0 版本开始添加了 $args 参数,增强了过滤器的灵活性。

代码示例

$term = apply_filters( 'pre_insert_term', $term, $taxonomy, $args );

📄 原文内容

Filters a term before it is sanitized and inserted into the database.

Parameters

$termstring|WP_Error
The term name to add, or a WP_Error object if there’s an error.
$taxonomystring
Taxonomy slug.
$argsarray|string
Array or query string of 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 = apply_filters( 'pre_insert_term', $term, $taxonomy, $args );

Changelog

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