sanitize_category_field()
云策文档标注
概述
sanitize_category_field() 函数用于清理单个分类键字段的数据,基于指定上下文进行过滤。它本质上是对 sanitize_term_field() 的封装,专门处理分类数据。
关键要点
- 函数 sanitize_category_field() 清理分类字段数据,接受字段名、值、分类 ID 和上下文作为参数。
- 内部调用 sanitize_term_field(),指定分类类型为 'category',确保数据安全。
- 参数包括 $field(分类键)、$value(分类值)、$cat_id(分类 ID)和 $context(过滤上下文如 'raw' 或 'display')。
- 返回清理后的值,适用于 WordPress 分类数据处理场景。
代码示例
function sanitize_category_field( $field, $value, $cat_id, $context ) {
return sanitize_term_field( $field, $value, $cat_id, 'category', $context );
}
原文内容
Sanitizes data in single category key field.
Parameters
$fieldstringrequired-
Category key to sanitize.
$valuemixedrequired-
Category value to sanitize.
$cat_idintrequired-
Category ID.
$contextstringrequired-
What filter to use,
'raw','display', etc.
Source
function sanitize_category_field( $field, $value, $cat_id, $context ) {
return sanitize_term_field( $field, $value, $cat_id, 'category', $context );
}
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |