Description

S'appuie sur la fonction sanitize_term_field() pour nettoyer un terme. La différence avec cette fonction est qu'elle nettoie tous les champs du terme.

Paramètres

$term

(array | object) (Requis) Le terme à vérifier.

$taxonomy

(string) (Requis) Le nom de la taxonomie à utiliser.

$context

(string) (Optionnel) Contexte dans lequel le terme est nettoyé. Accepte 'edit', 'db', 'display', 'attribute', ou 'js'.

Valeur par défaut : 'display'

Retourne

(array | object) Le terme avec tous ses champs nettoyés.

Structure de la fonction sanitize_term()

Définie dans le fichier wp-includes/taxonomy.php à la ligne 1524 :

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

Fonction utilisée par sanitize_term()

sanitize_term_field()

Nettoie la valeur d'un champ de terme basé sur le contexte.

Où trouver la fonction sanitize_term() dans le CMS Wordpress

Sources

Codex Wordpress : sanitize_term()

Autres fonctions dans le même fichier : wp-includes/taxonomy.php

Retour