diff --git wp-admin/includes/upgrade.php wp-admin/includes/upgrade.php
index 0d17d8f..78610be 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() { |
1959 | 1961 | } |
1960 | 1962 | |
1961 | 1963 | /** |
| 1964 | * Alter UNIQUE KEY for wp_term_taxonomy to include parent |
| 1965 | * |
| 1966 | * @since 3.7.0 |
| 1967 | */ |
| 1968 | function maybe_wp_tt_primary_key_parent() { |
| 1969 | global $wp_current_db_version, $wpdb; |
| 1970 | |
| 1971 | $keys = $wpdb->get_results( "SHOW KEYS FROM $wpdb->term_taxonomy WHERE Key_name = 'term_id_taxonomy'" ); |
| 1972 | |
| 1973 | if ( $wp_current_db_version >= 22448 && count( $keys ) ) |
| 1974 | $wpdb->query("ALTER TABLE $wpdb->term_taxonomy DROP INDEX term_id_taxonomy, ADD UNIQUE INDEX term_id_taxonomy_parent (`term_id`, `taxonomy`, `parent`)"); |
| 1975 | } |
| 1976 | |
| 1977 | /** |
1962 | 1978 | * Runs before the schema is upgraded. |
1963 | 1979 | * |
1964 | 1980 | * @since 2.9.0 |
diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
index 955369e..21d7e22 100644
|
|
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2087 | 2087 | } |
2088 | 2088 | |
2089 | 2089 | if ( $term_id = term_exists($slug) ) { |
2090 | | $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
| 2090 | $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); |
2091 | 2091 | // We've got an existing term in the same taxonomy, which matches the name of the new term: |
2092 | 2092 | if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { |
2093 | 2093 | // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. |
… |
… |
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2095 | 2095 | if ( in_array($name, $siblings) ) { |
2096 | 2096 | return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']); |
2097 | 2097 | } else { |
2098 | | $slug = wp_unique_term_slug($slug, (object) $args); |
2099 | | if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) |
2100 | | return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); |
2101 | | $term_id = (int) $wpdb->insert_id; |
| 2098 | $term_id = (int) $existing_term['term_id']; |
2102 | 2099 | } |
2103 | 2100 | } elseif ( $existing_term['name'] != $name ) { |
2104 | 2101 | // We've got an existing term, with a different name, Create the new term. |
… |
… |
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2126 | 2123 | do_action( 'edited_terms', $term_id, $taxonomy ); |
2127 | 2124 | } |
2128 | 2125 | |
2129 | | $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 ) ); |
| 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 AND tt.parent = %d", $taxonomy, $term_id, $parent ) ); |
2130 | 2127 | |
2131 | 2128 | if ( !empty($tt_id) ) |
2132 | 2129 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |