wp_insert_term_duplicate_term_check
云策文档标注
概述
wp_insert_term_duplicate_term_check 是一个 WordPress 过滤器,用于在创建分类术语时修改重复术语检查逻辑。它允许插件根据自定义的唯一性要求来绕过或调整默认检查。
关键要点
- 此过滤器在 wp_insert_term() 函数中调用,用于确认术语的唯一性,基于术语父级、分类法和 slug 的组合。
- 插件可以利用此过滤器实现不同的重复检查逻辑,例如忽略某些条件或添加额外验证。
- 过滤器参数包括 $duplicate_term(如果找到的重复术语行)、$term(要插入的术语)、$taxonomy(分类法名称)、$args(传递给 wp_insert_term() 的参数)和 $tt_id(新术语的 term_taxonomy_id)。
代码示例
$duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id );注意事项
- 此过滤器从 WordPress 5.1.0 版本开始引入。
- 默认唯一性检查基于术语父级、分类法和 slug 的组合,插件应确保自定义逻辑不会破坏数据完整性。
原文内容
Filters the duplicate term check that takes place during term creation.
Description
Term parent + taxonomy + slug combinations are meant to be unique, and wp_insert_term() performs a last-minute confirmation of this uniqueness before allowing a new term to be created. Plugins with different uniqueness requirements may use this filter to bypass or modify the duplicate-term check.
Parameters
$duplicate_termobject-
Duplicate term row from terms table, if found.
$termstring-
Term being inserted.
$taxonomystring-
Taxonomy name.
$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_ofstringSlug of the term to make this term an alias of.
Accepts a term slug.descriptionstringThe term description.parentintThe id of the parent term. Default 0.slugstringThe term slug to use.
$tt_idint-
term_taxonomy_id for the newly created term.
Source
$duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id );
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |