sanitize_term( array|object $term, string $taxonomy, string $context = 'display' )
Nettoie tous les champs d'un terme.
Paramètres
$term
(array|object)requisLe terme à vérifier.
$taxonomy
(string)requisLe nom de la taxonomie à utiliser.
$context
(string)optionnelContexte dans lequel le terme est nettoyé. Accepte 'edit', 'db', 'display', 'attribute', ou 'js'.
Valeur par défaut : 'display'
Description / Informations supplémentaires
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.
Retourne
(array|object) Le terme avec tous ses champs nettoyés.
Déclaration et structure de la fonction sanitize_term()
sanitize_term()
est déclarée dans le fichier wp-includes/taxonomy.php
à la ligne 1703 :
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ù est utilisée la fonction sanitize_term()
dans le CMS WordPress
Sources
Codex WordPress : sanitize_term()
Autres fonctions dans le même fichier : wp-includes/taxonomy.php