sanitize_term( array|object $term, string $taxonomy, string $context = 'display' ): array|object
- Since
- 2.3.0
- Source
wp-includes/taxonomy.php:1734
Sanitizes all term fields.
Description
Relies on sanitize_term_field() to sanitize the term. The difference is that this function will sanitize <strong>all</strong> fields. The context is based on sanitize_term_field(). The
$term is expected to be either an array or an object.Parameters
$termarray|object- The term to check.
$taxonomystring- The taxonomy name to use.
$contextstringoptional- Context in which to sanitize the term. Accepts 'raw', 'edit', 'db', 'display', 'rss', 'attribute', or 'js'. Default 'display'.Default:
'display'
Return
array|object- Term with all fields sanitized.
Uses · 1
- sanitize_term_field()Sanitizes the field value in the term based on the context.
Used by · 9
- WP_Term::__get()Getter.
- WP_Term::filter()Sanitizes term fields, according to the filter type provided.
- WP_Term::get_instance()Retrieve WP_Term instance.
- WP_Terms_List_Table::single_row()
- get_term()Gets all term data from database by term ID.
- get_term_to_edit()Sanitizes term for editing.
- sanitize_category()Sanitizes category data based on context.
- wp_insert_term()Adds a new term to the database.
- wp_update_term()Updates term based on arguments provided.
Source
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 ?? 0 ) : ( $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;}History
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.