| 2287 | | do_action( 'edit_terms', $term_id ); |
| 2288 | | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
| 2289 | | if ( empty($slug) ) { |
| 2290 | | $slug = sanitize_title($name, $term_id); |
| 2291 | | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
| 2292 | | } |
| 2293 | | do_action( 'edited_terms', $term_id ); |
| 2294 | | |
| | 2290 | |
| 2296 | | do_action( 'edit_term_taxonomy', $tt_id, $taxonomy ); |
| 2297 | | $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) ); |
| 2298 | | do_action( 'edited_term_taxonomy', $tt_id, $taxonomy ); |
| 2299 | | |
| | 2292 | $exist_tt = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS c FROM $wpdb->term_taxonomy AS tt WHERE term_id = %d", $term_id ) ); |
| | 2293 | |
| | 2294 | do_action( 'edit_terms', $term_id ); |
| 2303 | | $term_id = apply_filters('term_id_filter', $term_id, $tt_id); |
| | 2298 | $name_changed = in_array( 'name', $changed ); |
| | 2299 | $slug_changed = in_array( 'slug', $changed ); |
| | 2300 | |
| | 2301 | // create a new term if the current one exists in multiple taxonomies and its name or slug is changed |
| | 2302 | if ( $exist_tt > 1 && ( $name_changed || $slug_changed ) ) { |
| | 2303 | // create a unique slug |
| | 2304 | if ( $slug_changed ) |
| | 2305 | $slug = wp_unique_term_slug( $slug, (object) $args ); |
| | 2306 | elseif ( $name_changed ) |
| | 2307 | $slug = wp_unique_term_slug( sanitize_title( $name ), (object) $args ); |
| | 2308 | |
| | 2309 | $new_term = wp_insert_term( $name, $taxonomy, compact( 'slug', 'description', 'parent', 'term_group' ) ); |
| | 2310 | if ( is_wp_error( $new_term ) ) |
| | 2311 | return $new_term; |
| | 2312 | |
| | 2313 | $new_id = $new_term['term_id']; |
| | 2314 | $new_tt_id = $new_term['term_taxonomy_id']; |
| | 2315 | |
| | 2316 | // reassign posts to this new term |
| | 2317 | $wpdb->update( $wpdb->term_relationships, array( 'term_taxonomy_id' => $new_tt_id ), array( 'term_taxonomy_id' => $tt_id ) ); |
| | 2318 | wp_update_term_count( $new_tt_id, $taxonomy ); |
| | 2319 | wp_delete_term($term_id, $taxonomy); |
| | 2320 | |
| | 2321 | $term_id = $new_id; |
| | 2322 | $tt_id = $new_tt_id; |
| | 2323 | } else { |
| | 2324 | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
| | 2325 | do_action( 'edited_terms', $term_id ); |
| | 2327 | do_action( 'edit_term_taxonomy', $tt_id, $taxonomy ); |
| | 2328 | $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) ); |
| | 2329 | do_action( 'edited_term_taxonomy', $tt_id, $taxonomy ); |
| | 2330 | } |
| | 2331 | |
| | 2332 | $term_id = apply_filters('term_id_filter', $term_id, $tt_id); |