WordPress.org

Make WordPress Core

Ticket #17646: 17646.3.diff

File 17646.3.diff, 2.7 KB (added by kovshenin, 2 years ago)
  • wp-includes/taxonomy.php

     
    15801580 */ 
    15811581function sanitize_term($term, $taxonomy, $context = 'display') { 
    15821582 
    1583         if ( 'raw' == $context ) 
    1584                 return $term; 
     1583        $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); 
    15851584 
    1586         $fields = array('term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group'); 
    1587  
    15881585        $do_object = false; 
    15891586        if ( is_object($term) ) 
    15901587                $do_object = true; 
     
    16361633 * @return mixed sanitized field 
    16371634 */ 
    16381635function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { 
    1639         if ( 'parent' == $field  || 'term_id' == $field || 'count' == $field || 'term_group' == $field ) { 
    1640                 $value = (int) $value; 
    1641                 if ( $value < 0 ) 
    1642                         $value = 0; 
    1643         } 
     1636        $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); 
     1637        if ( in_array( $field, $int_fields ) ) 
     1638                $value = absint( $value ); 
    16441639 
    16451640        if ( 'raw' == $context ) 
    16461641                return $value; 
     
    19711966        $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"; 
    19721967 
    19731968        if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 
    1974                 $terms = array_merge($terms, $wpdb->get_results($query)); 
    1975                 update_term_cache($terms); 
     1969                $_terms = $wpdb->get_results( $query ); 
     1970                foreach ( $_terms as &$term ) 
     1971                        $term = sanitize_term( $term, $taxonomy, 'raw' ); 
     1972                $terms = array_merge( $terms, $_terms ); 
     1973                update_term_cache( $terms ); 
    19761974        } else if ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { 
    1977                 $terms = array_merge($terms, $wpdb->get_col($query)); 
     1975                $_terms = $wpdb->get_col( $query ); 
     1976                $_field = ( 'ids' == $fields ) ? 'term_id' : 'name'; 
     1977                foreach ( $_terms as &$term ) 
     1978                        $term = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' ); 
     1979                $terms = array_merge( $terms, $_terms ); 
    19781980        } else if ( 'tt_ids' == $fields ) { 
    19791981                $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"); 
     1982                foreach ( $terms as &$tt_id ) 
     1983                        $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. 
    19801984        } 
    19811985 
    19821986        if ( ! $terms )