WordPress.org

Make WordPress Core

Ticket #6593: is_term.2.diff

File is_term.2.diff, 2.9 KB (added by ryan, 6 years ago)
  • wp-includes/taxonomy.php

     
    761761function is_term($term, $taxonomy = '') { 
    762762        global $wpdb; 
    763763 
     764        $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; 
     765        $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; 
     766 
    764767        if ( is_int($term) ) { 
    765768                if ( 0 == $term ) 
    766769                        return 0; 
    767770                $where = 't.term_id = %d'; 
    768         } else { 
    769                 if ( '' === $term = sanitize_title($term) ) 
    770                         return 0; 
    771                 $where = 't.slug = %s'; 
     771                if ( !empty($taxonomy) ) 
     772                        return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); 
     773                else 
     774                        return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); 
    772775        } 
    773776 
    774         if ( !empty($taxonomy) ) 
    775                 return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $term, $taxonomy), ARRAY_A); 
     777        if ( '' === $slug = sanitize_title($term) ) 
     778                return 0; 
    776779 
    777         return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $term) ); 
     780        $where = 't.slug = %s'; 
     781        $else_where = 't.name = %s'; 
     782 
     783        if ( !empty($taxonomy) ) { 
     784                if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $slug, $taxonomy), ARRAY_A) ) 
     785                        return $result; 
     786                         
     787                return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s", $term, $taxonomy), ARRAY_A); 
     788        } 
     789 
     790        if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug) ) ) 
     791                return $result; 
     792 
     793        return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $term) ); 
    778794} 
    779795 
    780796/** 
  • wp-includes/version.php

     
    1515 * 
    1616 * @global int $wp_db_version 
    1717 */ 
    18 $wp_db_version = 8202; 
     18$wp_db_version = 8370; 
    1919 
    2020?> 
  • wp-admin/includes/schema.php

     
    1919 slug varchar(200) NOT NULL default '', 
    2020 term_group bigint(10) NOT NULL default 0, 
    2121 PRIMARY KEY  (term_id), 
    22  UNIQUE KEY slug (slug) 
     22 UNIQUE KEY slug (slug), 
     23 KEY name (name) 
    2324) $charset_collate; 
    2425CREATE TABLE $wpdb->term_taxonomy ( 
    2526 term_taxonomy_id bigint(20) NOT NULL auto_increment,