WordPress.org

Make WordPress Core

Ticket #6593: 6593.2.diff

File 6593.2.diff, 3.2 KB (added by DD32, 5 years ago)
  • wp-includes/taxonomy.php

     
    797797        $else_where = 't.name = %s'; 
    798798 
    799799        if ( !empty($taxonomy) ) { 
    800                 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) ) 
    801                         return $result; 
     800                if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT t.name, 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) ) { 
     801                        // slug == name = A slug was passed in, return straight up 
     802                        //If it was a Name that was passed however, Check that the name on the slug returned is the same as the name passed in. 
     803                        if ( ($slug == $term) || 0 == strcmp($result['name'], $term) ) 
     804                                return $result; 
     805                } 
    802806 
    803807                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); 
    804808        } 
    805809 
    806         if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug) ) ) 
    807                 return $result; 
     810        if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT term_id, name FROM $wpdb->terms as t WHERE $where", $slug), ARRAY_A ) ) 
     811                if ( ($slug == $term) || 0 == strcmp($result['name'], $term) ) //See comment in above block 
     812                        return $result['term_id']; 
    808813 
    809814        return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $term) ); 
    810815} 
     
    12651270                        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $alias->term_id ) ); 
    12661271                } 
    12671272        } 
     1273        if ( $term_id = is_term($name, $taxonomy) ) 
     1274                return new WP_Error('term_exists', __('A term by this name allready exists')); 
    12681275 
    1269         if ( ! $term_id = is_term($slug) ) { 
    1270                 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 
    1271                         return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 
    1272                 $term_id = (int) $wpdb->insert_id; 
    1273         } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { 
    1274                 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 
    1275                 // by incorporating parent slugs. 
    1276                 $slug = wp_unique_term_slug($slug, (object) $args); 
    1277                 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 
    1278                         return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 
    1279                 $term_id = (int) $wpdb->insert_id; 
    1280         } 
     1276        $slug = wp_unique_term_slug($slug, (object) $args); 
     1277        if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 
     1278                return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 
     1279        $term_id = (int) $wpdb->insert_id; 
    12811280 
    12821281        if ( empty($slug) ) { 
    12831282                $slug = sanitize_title($slug, $term_id);