Changeset 30494
- Timestamp:
- 11/21/2014 03:16:08 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r30155 r30494 307 307 add_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 ); 308 308 309 // Split term updates 310 add_filter( 'split_shared_term', '_wp_check_split_default_terms', 10, 4 ); 311 add_filter( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 ); 312 309 313 unset($filter, $action); -
trunk/src/wp-includes/taxonomy.php
r30493 r30494 4137 4137 4138 4138 /** 4139 * Check default categories when a term gets split to see if any of them need 4140 * to be updated. 4141 * 4142 * @since 4.1.0 4143 * @access private 4144 * 4145 * @param int $term_id ID of the formerly shared term. 4146 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. 4147 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. 4148 * @param string $taxonomy Taxonomy for the split term. 4149 */ 4150 function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 4151 if ( 'category' == $taxonomy ) { 4152 foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) { 4153 if ( $term_id == get_option( $option, -1 ) ) { 4154 update_option( $option, $new_term_id ); 4155 } 4156 } 4157 } 4158 } 4159 4160 /** 4161 * Check menu items when a term gets split to see if any of them need to be 4162 * updated. 4163 * 4164 * @since 4.1.0 4165 * @access private 4166 * 4167 * @param int $term_id ID of the formerly shared term. 4168 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. 4169 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. 4170 * @param string $taxonomy Taxonomy for the split term. 4171 */ 4172 function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 4173 global $wpdb; 4174 $post_ids = $wpdb->get_col( $wpdb->prepare( 4175 "SELECT m1.post_id 4176 FROM {$wpdb->postmeta} AS m1 4177 INNER JOIN {$wpdb->postmeta} AS m2 ON m2.post_id=m1.post_id 4178 INNER JOIN {$wpdb->postmeta} AS m3 ON m3.post_id=m1.post_id 4179 WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' ) 4180 AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = '%s' ) 4181 AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )", 4182 $taxonomy, 4183 $term_id 4184 ) ); 4185 4186 if ( $post_ids ) { 4187 foreach ( $post_ids as $post_id ) { 4188 update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id ); 4189 } 4190 } 4191 } 4192 4193 /** 4139 4194 * Generate a permalink for a taxonomy term archive. 4140 4195 * -
trunk/tests/phpunit/tests/term/splitSharedTerm.php
r30347 r30494 5 5 */ 6 6 class Tests_Term_SplitSharedTerm extends WP_UnitTestCase { 7 protected $t t_ids = array();7 protected $terms = array(); 8 8 9 9 public function setUp() { … … 41 41 ) ); 42 42 43 $this->t t_ids = array(44 't1' => $t1 ['term_taxonomy_id'],45 't2' => $t2 ['term_taxonomy_id'],46 't3' => $t3 ['term_taxonomy_id'],47 't2_child' => $t2_child ['term_taxonomy_id'],43 $this->terms = array( 44 't1' => $t1, 45 't2' => $t2, 46 't3' => $t3, 47 't2_child' => $t2_child, 48 48 ); 49 49 … … 56 56 */ 57 57 public function test_should_create_new_term_ids() { 58 $t1_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t1'], 'wptests_tax' );59 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );60 $t3_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t3'], 'wptests_tax_3' );58 $t1_term = get_term_by( 'term_taxonomy_id', $this->terms['t1']['term_taxonomy_id'], 'wptests_tax' ); 59 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 60 $t3_term = get_term_by( 'term_taxonomy_id', $this->terms['t3']['term_taxonomy_id'], 'wptests_tax_3' ); 61 61 62 62 $this->assertNotEquals( $t1_term->term_id, $t2_term->term_id ); … … 69 69 */ 70 70 public function test_should_retain_child_terms_when_using_get_terms_parent() { 71 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );71 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 72 72 $children = get_terms( 'wptests_tax_2', array( 73 73 'parent' => $t2_term->term_id, … … 75 75 ) ); 76 76 77 $this->assertEquals( $this->t t_ids['t2_child'], $children[0]->term_taxonomy_id );77 $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id ); 78 78 } 79 79 … … 82 82 */ 83 83 public function test_should_retain_child_terms_when_using_get_terms_child_of() { 84 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );84 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 85 85 $children = get_terms( 'wptests_tax_2', array( 86 86 'child_of' => $t2_term->term_id, … … 88 88 ) ); 89 89 90 $this->assertEquals( $this->t t_ids['t2_child'], $children[0]->term_taxonomy_id );90 $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id ); 91 91 } 92 92 … … 122 122 $this->assertEquals( array( $new_term_id ), $t2_children ); 123 123 } 124 125 /** 126 * @ticket 30335 127 */ 128 public function test_should_update_default_category_on_term_split() { 129 global $wpdb; 130 $t1 = wp_insert_term( 'Foo Default', 'category' ); 131 132 update_option( 'default_category', $t1['term_id'] ); 133 134 register_taxonomy( 'wptests_tax_5', 'post' ); 135 $t2 = wp_insert_term( 'Foo Default', 'wptests_tax_5' ); 136 137 // Manually modify because split terms shouldn't naturally occur. 138 $wpdb->update( $wpdb->term_taxonomy, 139 array( 'term_id' => $t1['term_id'] ), 140 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ), 141 array( '%d' ), 142 array( '%d' ) 143 ); 144 145 $this->assertEquals( $t1['term_id'], get_option( 'default_category', -1 ) ); 146 147 $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] ); 148 149 $this->assertNotEquals( $new_term_id, $t1['term_id'] ); 150 $this->assertEquals( $new_term_id, get_option( 'default_category', -1 ) ); 151 } 152 153 /** 154 * @ticket 30335 155 */ 156 public function test_should_update_menus_on_term_split() { 157 global $wpdb; 158 159 $t1 = wp_insert_term( 'Foo Menu', 'category' ); 160 161 register_taxonomy( 'wptests_tax_6', 'post' ); 162 $t2 = wp_insert_term( 'Foo Menu', 'wptests_tax_6' ); 163 164 // Manually modify because split terms shouldn't naturally occur. 165 $wpdb->update( $wpdb->term_taxonomy, 166 array( 'term_id' => $t1['term_id'] ), 167 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ), 168 array( '%d' ), 169 array( '%d' ) 170 ); 171 172 $menu_id = wp_create_nav_menu( rand_str() ); 173 $cat_menu_item = wp_update_nav_menu_item( $menu_id, 0, array( 174 'menu-item-type' => 'taxonomy', 175 'menu-item-object' => 'category', 176 'menu-item-object-id' => $t1['term_id'], 177 'menu-item-status' => 'publish' 178 ) ); 179 $this->assertEquals( $t1['term_id'], get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 180 181 $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] ); 182 $this->assertNotEquals( $new_term_id, $t1['term_id'] ); 183 $this->assertEquals( $new_term_id, get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 184 } 124 185 }
Note: See TracChangeset
for help on using the changeset viewer.