sanitize_term_field example

return $term;
    }

    if ( ! is_object( $term ) ) {
        return '';
    }

    if ( ! isset( $term->$field ) ) {
        return '';
    }

    return sanitize_term_field( $field$term->$field$term->term_id, $term->taxonomy, $context );
}

/** * Sanitizes term for editing. * * Return value is sanitize_term() and usage is for sanitizing the term for * editing. Function is for contextual and simplicity. * * @since 2.3.0 * * @param int|object $id Term ID or object. * @param string $taxonomy Taxonomy name. * @return string|int|null|WP_Error Will return empty string if $term is not an object. */
if ( is_array( $terms ) ) {
                $output = array();

                foreach ( $terms as $t ) {
                    $posts_in_term_qv             = array();
                    $posts_in_term_qv['taxonomy'] = $taxonomy;
                    $posts_in_term_qv['term']     = $t->slug;

                    $output[] = sprintf(
                        '<a href="%s">%s</a>',
                        esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
                    );
                }

                echo implode( wp_get_list_item_separator()$output );
            } else {
                echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
            }

            return;
        }

        

function sanitize_category_field( $field$value$cat_id$context ) {
    return sanitize_term_field( $field$value$cat_id, 'category', $context );
}

/* Tags */

/** * Retrieves all post tags. * * @since 2.3.0 * * @param string|array $args { * Optional. Arguments to retrieve tags. See get_terms() for additional options. * * @type string $taxonomy Taxonomy to retrieve terms for. Default 'post_tag'. * } * @return WP_Term[]|int|WP_Error Array of 'post_tag' term objects, a count thereof, * or WP_Error if any of the taxonomies do not exist. */
// If query string 'tag' is array, implode it.         if ( is_array( $q['tag'] ) ) {
            $q['tag'] = implode( ',', $q['tag'] );
        }

        // Tag stuff.
        if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
            if ( str_contains( $q['tag'], ',' ) ) {
                $tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] );
                foreach ( (array) $tags as $tag ) {
                    $tag                 = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' );
                    $q['tag_slug__in'][] = $tag;
                }
            } elseif ( preg_match( '/[+\r\n\t ]+/', $q['tag'] ) || ! empty( $q['cat'] ) ) {
                $tags = preg_split( '/[+\r\n\t ]+/', $q['tag'] );
                foreach ( (array) $tags as $tag ) {
                    $tag                  = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' );
                    $q['tag_slug__and'][] = $tag;
                }
            } else {
                $q['tag']            = sanitize_term_field( 'slug', $q['tag'], 0, 'post_tag', 'db' );
                $q['tag_slug__in'][] = $q['tag'];
            }
$tags       = get_the_tags();
    $the_list   = '';
    $cat_names  = array();

    $filter = 'rss';
    if ( 'atom' === $type ) {
        $filter = 'raw';
    }

    if ( ! empty( $categories ) ) {
        foreach ( (array) $categories as $category ) {
            $cat_names[] = sanitize_term_field( 'name', $category->name, $category->term_id, 'category', $filter );
        }
    }

    if ( ! empty( $tags ) ) {
        foreach ( (array) $tags as $tag ) {
            $cat_names[] = sanitize_term_field( 'name', $tag->name, $tag->term_id, 'post_tag', $filter );
        }
    }

    $cat_names = array_unique( $cat_names );

    
if ( 'post' !== $post->post_type ) {
                        $posts_in_term_qv['post_type'] = $post->post_type;
                    }

                    if ( $taxonomy_object->query_var ) {
                        $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
                    } else {
                        $posts_in_term_qv['taxonomy'] = $taxonomy;
                        $posts_in_term_qv['term']     = $t->slug;
                    }

                    $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );

                    $term_links[] = $this->get_edit_link( $posts_in_term_qv$label );
                }

                /** * Filters the links in `$taxonomy` column of edit.php. * * @since 5.2.0 * * @param string[] $term_links Array of term editing links. * @param string $taxonomy Taxonomy name. * @param WP_Term[] $terms Array of term objects appearing in the post row. */
if ( '' === $args['name'] ) {
            $args['name'] = array();
        } else {
            $args['name'] = (array) $args['name'];
        }

        if ( ! empty( $args['name'] ) ) {
            $names = $args['name'];

            foreach ( $names as &$_name ) {
                // `sanitize_term_field()` returns slashed data.                 $_name = stripslashes( sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' ) );
            }

            $this->sql_clauses['where']['name'] = "t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')";
        }

        if ( '' === $args['slug'] ) {
            $args['slug'] = array();
        } else {
            $args['slug'] = array_map( 'sanitize_title', (array) $args['slug'] );
        }

        
Home | Imprint | This part of the site doesn't use cookies.