Make WordPress Core

Ticket #36950: 36950.patch

File 36950.patch, 2.1 KB (added by spacedmonkey, 9 years ago)
  • src/wp-includes/taxonomy.php

     
    927927                return false;
    928928        }
    929929
    930         $tax_clause = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
    931 
    932930        if ( 'slug' == $field ) {
    933                 $_field = 't.slug';
    934931                $value = sanitize_title($value);
    935                 if ( empty($value) )
     932                if ( empty( $value ) ) {
    936933                        return false;
     934                }
     935                $terms = get_terms( array(
     936                        'taxonomy'   => $taxonomy,
     937                        'hide_empty' => false,
     938                        'number'     => 1,
     939                        'slug'       => $value
     940                ) );
     941                if ( empty( $terms ) || is_wp_error( $terms ) ) {
     942                        return false;
     943                }
     944                $term = array_shift( $terms );
    937945        } elseif ( 'name' == $field ) {
    938946                // Assume already escaped
    939947                $value = wp_unslash($value);
    940                 $_field = 't.name';
     948                $terms = get_terms( array(
     949                        'taxonomy'   => $taxonomy,
     950                        'hide_empty' => false,
     951                        'number'     => 1,
     952                        'name'       => $value
     953                ) );
     954                if ( empty( $terms ) || is_wp_error( $terms ) ) {
     955                        return false;
     956                }
     957                $term = array_shift( $terms );
    941958        } elseif ( 'term_taxonomy_id' == $field ) {
    942959                $value = (int) $value;
    943960                $_field = 'tt.term_taxonomy_id';
    944961
    945                 // No `taxonomy` clause when searching by 'term_taxonomy_id'.
    946                 $tax_clause = '';
     962                $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE $_field = %s", $value ) . " LIMIT 1" );
     963                if ( ! $term ) {
     964                        return false;
     965                }
    947966        } else {
    948967                $term = get_term( (int) $value, $taxonomy, $output, $filter );
    949968                if ( is_wp_error( $term ) || is_null( $term ) ) {
     
    952971                return $term;
    953972        }
    954973
    955         $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE $_field = %s", $value ) . " $tax_clause LIMIT 1" );
    956         if ( ! $term )
    957                 return false;
    958 
    959974        // In the case of 'term_taxonomy_id', override the provided `$taxonomy` with whatever we find in the db.
    960975        if ( 'term_taxonomy_id' === $field ) {
    961976                $taxonomy = $term->taxonomy;