edit_term_{$field}
云策文档标注
概述
edit_term_{$field} 是一个动态过滤器钩子,用于在术语字段被清理之前过滤其值。它允许开发者在术语编辑过程中修改字段数据。
关键要点
- 这是一个动态钩子,$field 部分指代术语字段名,如 'name' 或 'description'。
- 钩子接收三个参数:$value(字段值)、$term_id(术语ID)和 $taxonomy(分类法slug)。
- 主要用于 sanitize_term_field() 函数中,在清理术语字段前应用自定义过滤逻辑。
代码示例
$value = apply_filters( "edit_term_{$field}", $value, $term_id, $taxonomy );注意事项
- 钩子自 WordPress 2.3.0 版本引入,确保在兼容版本中使用。
- 使用时应确保 $field 参数正确匹配目标术语字段,以避免意外行为。
原文内容
Filters a term field to edit before it is sanitized.
Description
The dynamic portion of the hook name, $field, refers to the term field.
Parameters
$valuemixed-
Value of the term field.
$term_idint-
Term ID.
$taxonomystring-
Taxonomy slug.
Source
$value = apply_filters( "edit_term_{$field}", $value, $term_id, $taxonomy );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |