On this page
sanitize_term( array|object $term, string $taxonomy, string $context = 'display' ): array|object
Sanitizes all term fields.
Description
Relies on sanitize_term_field() to sanitize the term. The difference is that this function will sanitize all fields. The context is based on sanitize_term_field() .
The $term is expected to be either an array or an object.
Parameters
$termarray|object Required-
The term to check.
$taxonomystring Required-
The taxonomy name to use.
$contextstring Optional-
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.
Source
File: wp-includes/taxonomy.php. View all references
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
Uses
| Uses | Description |
|---|---|
| sanitize_term_field() wp-includes/taxonomy.php | Sanitizes the field value in the term based on the context. |
Used By
| Used By | Description |
|---|---|
| WP_Term::filter() wp-includes/class-wp-term.php | Sanitizes term fields, according to the filter type provided. |
| WP_Term::__get() wp-includes/class-wp-term.php | Getter. |
| WP_Term::get_instance() wp-includes/class-wp-term.php | Retrieve WP_Term instance. |
| WP_Terms_List_Table::single_row() wp-admin/includes/class-wp-terms-list-table.php | |
| sanitize_category() wp-includes/category.php | Sanitizes category data based on context. |
| wp_update_term() wp-includes/taxonomy.php | Updates term based on arguments provided. |
| wp_insert_term() wp-includes/taxonomy.php | Adds a new term to the database. |
| get_term_to_edit() wp-includes/taxonomy.php | Sanitizes term for editing. |
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/sanitize_term