diff --git wp-admin/includes/upgrade.php wp-admin/includes/upgrade.php
index 7ba271a..8c8e3be 100644
|
|
function upgrade_all() { |
404 | 404 | |
405 | 405 | maybe_disable_link_manager(); |
406 | 406 | |
| 407 | maybe_wp_tt_primary_key_parent(); |
| 408 | |
407 | 409 | maybe_disable_automattic_widgets(); |
408 | 410 | |
409 | 411 | update_option( 'db_version', $wp_db_version ); |
… |
… |
function maybe_disable_link_manager() { |
1953 | 1955 | } |
1954 | 1956 | |
1955 | 1957 | /** |
| 1958 | * Alter UNIQUE KEY for wp_term_taxonomy to include parent |
| 1959 | * |
| 1960 | * @since 3.6.0 |
| 1961 | */ |
| 1962 | function 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 | /** |
1956 | 1972 | * Runs before the schema is upgraded. |
1957 | 1973 | * |
1958 | 1974 | * @since 2.9.0 |
diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
index d527ee1..b7e179b 100644
|
|
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2084 | 2084 | } |
2085 | 2085 | |
2086 | 2086 | 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 ); |
2088 | 2088 | // We've got an existing term in the same taxonomy, which matches the name of the new term: |
2089 | 2089 | if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { |
2090 | 2090 | // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. |
… |
… |
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2092 | 2092 | if ( in_array($name, $siblings) ) { |
2093 | 2093 | return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']); |
2094 | 2094 | } 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']; |
2099 | 2096 | } |
2100 | 2097 | } elseif ( $existing_term['name'] != $name ) { |
2101 | 2098 | // We've got an existing term, with a different name, Create the new term. |
… |
… |
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2123 | 2120 | do_action( 'edited_terms', $term_id ); |
2124 | 2121 | } |
2125 | 2122 | |
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 ) ); |
2127 | 2124 | |
2128 | 2125 | if ( !empty($tt_id) ) |
2129 | 2126 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |