diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index 5846844..44447e8 100644
|
|
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
2455 | 2455 | // The alias isn't in a group, so let's create a new one and firstly add the alias term to it. |
2456 | 2456 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
2457 | 2457 | |
2458 | | /** |
2459 | | * Fires immediately before the given terms are edited. |
2460 | | * |
2461 | | * @since 2.9.0 |
2462 | | * |
2463 | | * @param int $term_id Term ID. |
2464 | | * @param string $taxonomy Taxonomy slug. |
2465 | | */ |
2466 | | do_action( 'edit_terms', $alias->term_id, $taxonomy ); |
2467 | | $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) ); |
2468 | | |
2469 | | /** |
2470 | | * Fires immediately after the given terms are edited. |
2471 | | * |
2472 | | * @since 2.9.0 |
2473 | | * |
2474 | | * @param int $term_id Term ID |
2475 | | * @param string $taxonomy Taxonomy slug. |
2476 | | */ |
2477 | | do_action( 'edited_terms', $alias->term_id, $taxonomy ); |
| 2458 | wp_update_term( $alias->term_id, $taxonomy, array( |
| 2459 | 'term_group' => $term_group, |
| 2460 | ) ); |
2478 | 2461 | } |
2479 | 2462 | } |
2480 | 2463 | |
… |
… |
function wp_update_term( $term_id, $taxonomy, $args = array() ) { |
3004 | 2987 | return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
3005 | 2988 | } |
3006 | 2989 | |
3007 | | /** This action is documented in wp-includes/taxonomy.php */ |
| 2990 | /** |
| 2991 | * Fires immediately before the given terms are edited. |
| 2992 | * |
| 2993 | * @since 2.9.0 |
| 2994 | * |
| 2995 | * @param int $term_id Term ID. |
| 2996 | * @param string $taxonomy Taxonomy slug. |
| 2997 | */ |
3008 | 2998 | do_action( 'edit_terms', $term_id, $taxonomy ); |
3009 | 2999 | $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
3010 | 3000 | if ( empty($slug) ) { |
… |
… |
function wp_update_term( $term_id, $taxonomy, $args = array() ) { |
3012 | 3002 | $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
3013 | 3003 | } |
3014 | 3004 | |
3015 | | /** This action is documented in wp-includes/taxonomy.php */ |
| 3005 | /** |
| 3006 | * Fires immediately after the given terms are edited. |
| 3007 | * |
| 3008 | * @since 2.9.0 |
| 3009 | * |
| 3010 | * @param int $term_id Term ID |
| 3011 | * @param string $taxonomy Taxonomy slug. |
| 3012 | */ |
3016 | 3013 | do_action( 'edited_terms', $term_id, $taxonomy ); |
3017 | 3014 | |
3018 | 3015 | $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) ); |
diff --git tests/phpunit/tests/term.php tests/phpunit/tests/term.php
index 2576157..8bd0706 100644
|
|
class Tests_Term extends WP_UnitTestCase { |
244 | 244 | $this->assertEquals( 0, term_exists(NULL) ); |
245 | 245 | } |
246 | 246 | |
| 247 | public function test_wp_insert_term_alias_of_no_term_group() { |
| 248 | register_taxonomy( 'wptests_tax', 'post' ); |
| 249 | $original_term_id = $this->factory->term->create( array( |
| 250 | 'taxonomy' => 'wptests_tax', |
| 251 | ) ); |
| 252 | $original_term = get_term( $original_term_id, 'wptests_tax' ); |
| 253 | |
| 254 | $created_term_ids = wp_insert_term( 'Foo', 'wptests_tax', array( |
| 255 | 'alias_of' => $original_term->slug, |
| 256 | ) ); |
| 257 | $created_term = get_term( $created_term_ids['term_id'], 'wptests_tax' ); |
| 258 | |
| 259 | $updated_original_term = get_term( $original_term->term_id, 'wptests_tax' ); |
| 260 | |
| 261 | $term = get_term( $created_term_ids['term_id'], 'wptests_tax' ); |
| 262 | _unregister_taxonomy( 'wptests_tax' ); |
| 263 | |
| 264 | $this->assertSame( 0, $original_term->term_group ); |
| 265 | $this->assertNotEmpty( $created_term->term_group ); |
| 266 | $this->assertSame( $created_term->term_group, $updated_original_term->term_group ); |
| 267 | } |
| 268 | |
247 | 269 | public function test_wp_insert_term_duplicate_name_slug_non_hierarchical() { |
248 | 270 | register_taxonomy( 'foo', 'post', array() ); |
249 | 271 | |