WordPress.org

Make WordPress Core

Ticket #17646: 17646.sw.2.diff

File 17646.sw.2.diff, 2.6 KB (added by simonwheatley, 3 years ago)

Cleaned up DD32's patch so it works on the current trunk

  • wp-includes/taxonomy.php

     
    15611561 */ 
    15621562function sanitize_term($term, $taxonomy, $context = 'display') { 
    15631563 
    1564         if ( 'raw' == $context ) 
    1565                 return $term; 
     1564        // if ( 'raw' == $context ) //sanitize_term_field returns when raw after int'ing appropriate fields. 
     1565        //      return $term; 
    15661566 
    1567         $fields = array('term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group'); 
     1567        $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id' ); 
    15681568 
    15691569        $do_object = false; 
    15701570        if ( is_object($term) ) 
     
    16171617 * @return mixed sanitized field 
    16181618 */ 
    16191619function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { 
    1620         if ( 'parent' == $field  || 'term_id' == $field || 'count' == $field || 'term_group' == $field ) { 
     1620        if ( 'parent' == $field  || 'term_id' == $field || 'count' == $field || 'term_group' == $field || 'term_taxonomy_id' == $field ) { 
    16211621                $value = (int) $value; 
    16221622                if ( $value < 0 ) 
    16231623                        $value = 0; 
     
    19501950        $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 
    19511951 
    19521952        if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 
    1953                 $terms = array_merge($terms, $wpdb->get_results($query)); 
     1953                $_terms = $wpdb->get_results($query); 
     1954                foreach ( $_terms as &$term ) 
     1955                        $term = sanitize_term($term, $taxonomy, 'raw'); 
     1956                $terms = array_merge($terms, $_terms); 
    19541957                update_term_cache($terms); 
    19551958        } else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { 
    1956                 $terms = array_merge($terms, $wpdb->get_col($query)); 
     1959                $_terms = $wpdb->get_col($query); 
     1960                $_field = ('ids' == $fields) ? 'term_id' : 'name'; 
     1961                foreach ( $_terms as &$term ) 
     1962                        $term = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw'); 
     1963                $terms = array_merge($terms, $_terms); 
    19571964        } else if ( 'tt_ids' == $fields ) { 
    19581965                $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"); 
     1966                foreach ( $terms as &$tt_id ) 
     1967                        $tt_id = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw'); // 0 should be the term id, however is not needed when using raw context. 
    19591968        } 
    19601969 
    19611970        if ( ! $terms )