WordPress.org

Make WordPress Core

Ticket #5034: 5034.diff

File 5034.diff, 3.3 KB (added by wonderboymusic, 5 years ago)
  • wp-admin/includes/upgrade.php

    diff --git wp-admin/includes/upgrade.php wp-admin/includes/upgrade.php
    index 7ba271a..8c8e3be 100644
    function upgrade_all() { 
    404404 
    405405        maybe_disable_link_manager(); 
    406406 
     407        maybe_wp_tt_primary_key_parent(); 
     408 
    407409        maybe_disable_automattic_widgets(); 
    408410 
    409411        update_option( 'db_version', $wp_db_version ); 
    function maybe_disable_link_manager() { 
    19531955} 
    19541956 
    19551957/** 
     1958 * Alter UNIQUE KEY for wp_term_taxonomy to include parent 
     1959 * 
     1960 * @since 3.6.0 
     1961 */ 
     1962function maybe_wp_tt_primary_key_parent() { 
     1963        global $wp_current_db_version, $wpdb; 
     1964 
     1965        $keys = $wpdb->get_results( "SHOW KEYS FROM $wpdb->term_taxonomy WHERE Key_name = 'term_id_taxonomy'" ); 
     1966 
     1967        if ( $wp_current_db_version >= 22441 && count( $keys ) ) 
     1968                $wpdb->query("ALTER TABLE $wpdb->term_taxonomy DROP INDEX term_id_taxonomy, ADD UNIQUE INDEX term_id_taxonomy_parent (`term_id`, `taxonomy`, `parent`)"); 
     1969} 
     1970 
     1971/** 
    19561972 * Runs before the schema is upgraded. 
    19571973 * 
    19581974 * @since 2.9.0 
  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index d527ee1..b7e179b 100644
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    20842084        } 
    20852085 
    20862086        if ( $term_id = term_exists($slug) ) { 
    2087                 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 
     2087                $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 
    20882088                // We've got an existing term in the same taxonomy, which matches the name of the new term: 
    20892089                if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { 
    20902090                        // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    20922092                        if ( in_array($name, $siblings) ) { 
    20932093                                return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']); 
    20942094                        } else { 
    2095                                 $slug = wp_unique_term_slug($slug, (object) $args); 
    2096                                 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) 
    2097                                         return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 
    2098                                 $term_id = (int) $wpdb->insert_id; 
     2095                                $term_id = (int) $existing_term['term_id']; 
    20992096                        } 
    21002097                } elseif ( $existing_term['name'] != $name ) { 
    21012098                        // We've got an existing term, with a different name, Create the new term. 
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    21232120                do_action( 'edited_terms', $term_id ); 
    21242121        } 
    21252122 
    2126         $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); 
     2123        $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d AND tt.parent = %d", $taxonomy, $term_id, $parent ) ); 
    21272124 
    21282125        if ( !empty($tt_id) ) 
    21292126                return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);