2385 | | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
2386 | | if ( empty($slug) ) { |
2387 | | $slug = sanitize_title($name, $term_id); |
| 2386 | |
| 2387 | $tt_id_sql = "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"; |
| 2388 | |
| 2389 | // Don't indiscriminately update the term name if the term is being used by another taxonomy |
| 2390 | $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(taxonomy) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) ); |
| 2391 | |
| 2392 | // if there are multiple instances, make the updated term a new term so we only have to alter one term_taxonomy row's term_id |
| 2393 | if ( $count > 1 ) { |
| 2394 | $old_tt_id = $wpdb->get_var( $wpdb->prepare( $tt_id_sql, $taxonomy, $term_id ) ); |
| 2395 | $term_ids = wp_insert_term( $name, $taxonomy, $args ); |
| 2396 | if ( ! is_wp_error( $term_ids ) ) { |
| 2397 | $new_tt_id = $term_ids['term_taxonomy_id']; |
| 2398 | // since wp_insert_term creates a new term_tax entry, we need to delete our old one after updating term_rels |
| 2399 | $wpdb->update( $wpdb->term_relationships, array( 'term_taxonomy_id' => $new_tt_id ), array( 'term_taxonomy_id' => $old_tt_id ) ); |
| 2400 | wp_delete_term( $term_id, $taxonomy ); |
| 2401 | _update_generic_term_count( array( $new_tt_id ), get_taxonomy( $taxonomy ) ); |
| 2402 | _update_post_term_count( array( $new_tt_id ), get_taxonomy( $taxonomy ) ); |
| 2403 | // reset term_id to new term_id |
| 2404 | $term_id = $term_ids['term_id']; |
| 2405 | } else { |
| 2406 | return $term_ids; |
| 2407 | } |
| 2408 | } else { |
| 2409 | $wpdb->update( $wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
| 2410 | } |
| 2411 | |
| 2412 | if ( empty( $slug ) ) { |
| 2413 | $slug = sanitize_title( $name, $term_id ); |