sanitize_term example

return new WP_Error( 'invalid_term', __( 'Empty Term.' ) );
    }

    if ( $taxonomy && ! taxonomy_exists( $taxonomy ) ) {
        return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
    }

    if ( $term instanceof WP_Term ) {
        $_term = $term;
    } elseif ( is_object( $term ) ) {
        if ( empty( $term->filter ) || 'raw' === $term->filter ) {
            $_term = sanitize_term( $term$taxonomy, 'raw' );
            $_term = new WP_Term( $_term );
        } else {
            $_term = WP_Term::get_instance( $term->term_id );
        }
    } else {
        $_term = WP_Term::get_instance( $term$taxonomy );
    }

    if ( is_wp_error( $_term ) ) {
        return $_term;
    } elseif ( ! $_term ) {
        
/** * Sanitizes category data based on context. * * @since 2.3.0 * * @param object|array $category Category data. * @param string $context Optional. Default 'display'. * @return object|array Same type as $category with sanitized data for safe use. */
function sanitize_category( $category$context = 'display' ) {
    return sanitize_term( $category, 'category', $context );
}

/** * Sanitizes data in single category key field. * * @since 2.3.0 * * @param string $field Category key to sanitize. * @param mixed $value Category value to sanitize. * @param int $cat_id Category ID. * @param string $context What filter to use, 'raw', 'display', etc. * @return mixed Value after $value has been sanitized. */


            if ( ! $_term ) {
                return false;
            }

            // Don't return terms from invalid taxonomies.             if ( ! taxonomy_exists( $_term->taxonomy ) ) {
                return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
            }

            $_term = sanitize_term( $_term$_term->taxonomy, 'raw' );

            // Don't cache terms that are shared between taxonomies.             if ( 1 === count( $terms ) ) {
                wp_cache_add( $term_id$_term, 'terms' );
            }
        }

        $term_obj = new WP_Term( $_term );
        $term_obj->filter( $term_obj->filter );

        return $term_obj;
    }

        }
    }

    /** * @global string $taxonomy * @param WP_Term $tag Term object. * @param int $level */
    public function single_row( $tag$level = 0 ) {
        global $taxonomy;
        $tag = sanitize_term( $tag$taxonomy );

        $this->level = $level;

        if ( $tag->parent ) {
            $count = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
            $level = 'level-' . $count;
        } else {
            $level = 'level-0';
        }

        echo '<tr id="tag-' . $tag->term_id . '" class="' . $level . '">';
        
Home | Imprint | This part of the site doesn't use cookies.