sanitize_term

Definition:
function sanitize_term($term, $taxonomy, $context = 'display') {}

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().

Parameters

  • array|object $term: The term to check
  • string $taxonomy: The taxonomy name to use
  • string $context: Default is ‘display’.

Return values

returns:with all fields sanitized

Source code

function sanitize_term($term, $taxonomy, $context = 'display') {



	if ( 'raw' == $context )

		return $term;



	$fields = array('term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group');



	$do_object = false;

	if ( is_object($term) )

		$do_object = true;



	$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;

}

2785

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: