wppaste
WordPress

sanitize_term( array|object $term, string $taxonomy, string $context = 'display' ): array|object

Since
2.3.0
Source
wp-includes/taxonomy.php:1721
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

Used by · 9

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.