sanitize_term( array|object $term, string $taxonomy, string $context = 'display' )
Sanitize Term all fields.
Description Description
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.
Parameters Parameters
- $term
-
(array|object) (Required) The term to check.
- $taxonomy
-
(string) (Required) The taxonomy name to use.
- $context
-
(string) (Optional) Context in which to sanitize the term. Accepts 'edit', 'db', 'display', 'attribute', or 'js'.
Default value: 'display'
Return Return
(array|object) Term with all fields sanitized.
Source Source
File: wp-includes/taxonomy.php
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 | 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 ; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |