wp_update_term_parent
云策文档标注
概述
wp_update_term_parent 是一个 WordPress 过滤器钩子,用于在更新分类术语时过滤其父术语 ID,以防止层级循环问题。
关键要点
- 这是一个过滤器钩子,允许开发者在更新术语时检查和修改父术语 ID。
- 主要用途是检测和避免因父术语设置不当导致的层级循环。
- 参数包括父术语 ID、术语 ID、分类法 slug、更新参数数组和传递给 wp_update_term() 的原始参数。
- 在 wp_update_term() 函数内部调用,用于处理术语更新逻辑。
代码示例
$parent = (int) apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args );注意事项
- 此钩子自 WordPress 3.1.0 版本引入。
- 开发者应利用此钩子验证父术语设置,确保分类层级结构的正确性。
原文内容
Filters the term parent.
Description
Hook to this filter to see if it will cause a hierarchy loop.
Parameters
$parent_termint-
ID of the parent term.
$term_idint-
Term ID.
$taxonomystring-
Taxonomy slug.
$parsed_argsarray-
An array of potentially altered update arguments for the given term.
$argsarray-
Arguments passed to wp_update_term() .
More Arguments from wp_update_term( … $args )
Array of arguments for updating 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.
Source
$parent = (int) apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args );
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |