sanitize_term
函数
sanitize_term ( $term, $taxonomy, $context = 'display' )
- 参数
-
-
(array|object)
$term
The term to check.- Required: 是
-
(string)
$taxonomy
The taxonomy name to use.- Required: 是
-
(string)
$context
Optional. Context in which to sanitize the term. Accepts ‘raw’, ‘edit’, ‘db’, ‘display’, ‘rss’, ‘attribute’, or ‘js’. Default ‘display’.- Required: 否
- Default: ‘display’
-
(array|object)
- 返回值
-
- (array|object) Term with all fields sanitized.
- 定义位置
-
-
wp-includes/taxonomy.php
, line 1639
-
wp-includes/taxonomy.php
- 引入
- 2.3.0
- 弃用
- –
Sanitizes all term fields.
Relies on sanitize_term_field() to sanitize the term. The difference is that
this function will sanitize **all** fields. The context is based
on sanitize_term_field().
The `$term` is expected to be either an array or an object.
function sanitize_term( $term, $taxonomy, $context = 'display' ) { $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); $do_object = is_object( $term ); $term_id = $do_object ? $term->term_id : ( isset( $term['term_id'] ) ? $term['term_id'] : 0 ); foreach ( (array) $fields as $field ) { if ( $do_object ) { if ( isset( $term->$field ) ) { $term->$field = sanitize_term_field( $field, $term->$field, $term_id, $taxonomy, $context ); } } else { if ( isset( $term[ $field ] ) ) { $term[ $field ] = sanitize_term_field( $field, $term[ $field ], $term_id, $taxonomy, $context ); } } } if ( $do_object ) { $term->filter = $context; } else { $term['filter'] = $context; } return $term; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。