WordPress at a glance

sanitize_term() WP 1.0

Sanitize Term all fields.

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.

Works based on: sanitize_term_field()
✈ 1 time = 0.000771s = slow | 50000 times = 6s = fast

No Hooks.

Return

Array/Object. Term with all fields sanitized.

Usage

sanitize_term( $term, $taxonomy, $context );
$term(array/object) (required)
The term to check.
$taxonomy(string) (required)
The taxonomy name to use.
$context(string)
Context in which to sanitize the term. Accepts 'edit', 'db', 'display', 'attribute', or 'js'.
Default: 'display'

Code of sanitize_term: wp-includes/taxonomy.php VER 4.9.8

<?php
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;
}

Related Functions

From tag: sanitize_

More from category: Any taxonomy

No comments
    Hello, !     Log In . Register