﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
21275,Insert new term on wp_update_term when multiple taxonomies share term being updated,wonderboymusic,,"This bug, and it is a bug, has had real-world consequences for our site management. Here is the scenario, which I think we are all familiar with:

1) I add a term for post_tag: Brooklyn[[BR]]
2) I add a term for taxonomy, location: Brooklyn[[BR]]
3) I add a term for taxonomy, radio_station: Brooklyn[[BR]]
4) I change the name of my radio_station: Brooklyn's Finest[[BR]]
5) My tag and location are now called: Brooklyn's Finest[[BR]]

This sucks. I have if / else'd a few lines of wp_update_term to take this scenario into account. Here is what it does:

1) checks the number of taxonomies a term belongs to[[BR]]
2) If that number is more than 1:
- stores reference to old_tt_id
- calls wp_insert_term (which wil handle dupe and slug checking, etc)
- updates the term_relationships for posts - old_tt_id becomes new_tt_id generated by wp_insert_term
- calls wp_delete_term on the old term_id which will delete the term cache
- changes the function internal $term_id to whatever wp_insert_term returned
3) If count is not more than one, function runs like normal

The result:[[BR]]
The post_tag and location remain ""Brooklyn""[[BR]]
The radio_station is ""renamed"" to ""Brooklyn's Finest""[[BR]]

Here is the code stub you can use to test this:

{{{
add_action( 'init', function () {
    
    register_taxonomy( 'radio_station', 'post', array( 
        'labels' => array( 'name' => 'Radio Stations' )
    ) );
    
} );
}}}",defect (bug),closed,normal,,Taxonomy,2.3,major,duplicate,has-patch,
