sanitize_term_field

The timeline below displays how wordpress function sanitize_term_field has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Sanitizes the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $context  Context in which to sanitize the term field.
 *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
 *                         'attribute', or 'js'. Default 'display'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    // Restore the type for integer fields after esc_attr().
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
    }
    return $value;
}

WordPress Version: 5.9

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy name.
 * @param string $context  Context in which to sanitize the term field.
 *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
 *                         'attribute', or 'js'. Default 'display'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the hook name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    // Restore the type for integer fields after esc_attr().
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
    }
    return $value;
}

WordPress Version: 5.8

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field.
 *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
 *                         'attribute', or 'js'. Default 'display'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    // Restore the type for integer fields after esc_attr().
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
    }
    return $value;
}

WordPress Version: 5.7

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field.
 *                         Accepts 'raw', 'edit', 'db', 'display', 'rss',
 *                         'attribute', or 'js'. Default 'display'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 5.5

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields, true)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 5.4

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters.
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 5.3

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    $context = strtolower($context);
    if ('raw' === $context) {
        return $value;
    }
    if ('edit' === $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' === $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' === $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' === $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' === $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' === $context) {
        $value = esc_attr($value);
    } elseif ('js' === $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 5.1

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
            // textarea_escaped
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' == $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' == $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } elseif ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 4.6

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filters a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filters the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' == $context) {
        /**
         * Filters a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filters a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filters the category nicename before it is sanitized.
             *
             * Use the {@see 'pre_$taxonomy_$field'} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' == $context) {
        /**
         * Filters the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filters the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filters the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filters the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } elseif ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 4.3

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @param string $field    Term field to sanitize.
 * @param string $value    Search for this term value.
 * @param int    $term_id  Term ID.
 * @param string $taxonomy Taxonomy Name.
 * @param string $context  Context in which to sanitize the term field. Accepts 'edit', 'db', 'display',
 *                         'attribute', or 'js'.
 * @return mixed Sanitized field.
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filter a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filter the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' == $context) {
        /**
         * Filter a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filter a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filter the category nicename before it is sanitized.
             *
             * Use the pre_{$taxonomy}_{$field} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' == $context) {
        /**
         * Filter the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filter the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filter the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filter the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } elseif ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 4.2

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $field Term field to sanitize
 * @param string $value Search for this term value
 * @param int $term_id Term ID
 * @param string $taxonomy Taxonomy Name
 * @param string $context Either edit, db, display, attribute, or js.
 * @return mixed sanitized field
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filter a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filter the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } elseif ('db' == $context) {
        /**
         * Filter a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filter a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filter the category nicename before it is sanitized.
             *
             * Use the pre_{$taxonomy}_{$field} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } elseif ('rss' == $context) {
        /**
         * Filter the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filter the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and $field, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filter the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filter the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and $field, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } elseif ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 4.1

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $field Term field to sanitize
 * @param string $value Search for this term value
 * @param int $term_id Term ID
 * @param string $taxonomy Taxonomy Name
 * @param string $context Either edit, db, display, attribute, or js.
 * @return mixed sanitized field
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filter a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filter the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } else if ('db' == $context) {
        /**
         * Filter a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filter a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, `$taxonomy` and `$field`, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filter the category nicename before it is sanitized.
             *
             * Use the pre_{$taxonomy}_{$field} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } else if ('rss' == $context) {
        /**
         * Filter the term field for use in RSS.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filter the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, `$taxonomy`, and $field, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filter the term field sanitized for display.
         *
         * The dynamic portion of the filter name, `$field`, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filter the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, `$taxonomy`, and $field, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } else if ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 3.9

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @since 2.3.0
 *
 * @uses $wpdb
 *
 * @param string $field Term field to sanitize
 * @param string $value Search for this term value
 * @param int $term_id Term ID
 * @param string $taxonomy Taxonomy Name
 * @param string $context Either edit, db, display, attribute, or js.
 * @return mixed sanitized field
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        /**
         * Filter a term field to edit before it is sanitized.
         *
         * The dynamic portion of the filter name, $field, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed $value     Value of the term field.
         * @param int   $term_id   Term ID.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        /**
         * Filter the taxonomy field to edit before it is sanitized.
         *
         * The dynamic portions of the filter name, $taxonomy, and $field, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value   Value of the taxonomy field to edit.
         * @param int   $term_id Term ID.
         */
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } else if ('db' == $context) {
        /**
         * Filter a term field value before it is sanitized.
         *
         * The dynamic portion of the filter name, $field, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        /**
         * Filter a taxonomy field before it is sanitized.
         *
         * The dynamic portions of the filter name, $taxonomy, and $field, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            /**
             * Filter the category nicename before it is sanitized.
             *
             * Use the pre_{$taxonomy}_{$field} hook instead.
             *
             * @since 2.0.3
             *
             * @param string $value The category nicename.
             */
            $value = apply_filters('pre_category_nicename', $value);
        }
    } else if ('rss' == $context) {
        /**
         * Filter the term field for use in RSS.
         *
         * The dynamic portion of the filter name, $field, refers to the term field.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param string $taxonomy Taxonomy slug.
         */
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        /**
         * Filter the taxonomy field for use in RSS.
         *
         * The dynamic portions of the hook name, $taxonomy, and $field, refer
         * to the taxonomy slug and field name, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed $value Value of the taxonomy field.
         */
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        /**
         * Filter the term field sanitized for display.
         *
         * The dynamic portion of the filter name, $field, refers to the term field name.
         *
         * @since 2.3.0
         *
         * @param mixed  $value    Value of the term field.
         * @param int    $term_id  Term ID.
         * @param string $taxonomy Taxonomy slug.
         * @param string $context  Context to retrieve the term field value.
         */
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        /**
         * Filter the taxonomy field sanitized for display.
         *
         * The dynamic portions of the filter name, $taxonomy, and $field, refer
         * to the taxonomy slug and taxonomy field, respectively.
         *
         * @since 2.3.0
         *
         * @param mixed  $value   Value of the taxonomy field.
         * @param int    $term_id Term ID.
         * @param string $context Context to retrieve the taxonomy field value.
         */
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } else if ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 3.8

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @uses $wpdb
 *
 * @param string $field Term field to sanitize
 * @param string $value Search for this term value
 * @param int $term_id Term ID
 * @param string $taxonomy Taxonomy Name
 * @param string $context Either edit, db, display, attribute, or js.
 * @return mixed sanitized field
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id');
    if (in_array($field, $int_fields)) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } else if ('db' == $context) {
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            $value = apply_filters('pre_category_nicename', $value);
        }
    } else if ('rss' == $context) {
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } else if ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}

WordPress Version: 3.7

/**
 * Cleanse the field value in the term based on the context.
 *
 * Passing a term field value through the function should be assumed to have
 * cleansed the value for whatever context the term field is going to be used.
 *
 * If no context or an unsupported context is given, then default filters will
 * be applied.
 *
 * There are enough filters for each context to support a custom filtering
 * without creating your own filter function. Simply create a function that
 * hooks into the filter you need.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @uses $wpdb
 *
 * @param string $field Term field to sanitize
 * @param string $value Search for this term value
 * @param int $term_id Term ID
 * @param string $taxonomy Taxonomy Name
 * @param string $context Either edit, db, display, attribute, or js.
 * @return mixed sanitized field
 */
function sanitize_term_field($field, $value, $term_id, $taxonomy, $context)
{
    if ('parent' == $field || 'term_id' == $field || 'count' == $field || 'term_group' == $field) {
        $value = (int) $value;
        if ($value < 0) {
            $value = 0;
        }
    }
    if ('raw' == $context) {
        return $value;
    }
    if ('edit' == $context) {
        $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
        $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
        if ('description' == $field) {
            $value = esc_html($value);
        } else {
            $value = esc_attr($value);
        }
    } else if ('db' == $context) {
        $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
        $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
        // Back compat filters
        if ('slug' == $field) {
            $value = apply_filters('pre_category_nicename', $value);
        }
    } else if ('rss' == $context) {
        $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
        $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
    } else {
        // Use display filters by default.
        $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
        $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
    }
    if ('attribute' == $context) {
        $value = esc_attr($value);
    } else if ('js' == $context) {
        $value = esc_js($value);
    }
    return $value;
}