Ticket #33187: 33187.diff
File 33187.diff, 6.2 KB (added by , 10 years ago) |
---|
-
src/wp-admin/nav-menus.php
diff --git src/wp-admin/nav-menus.php src/wp-admin/nav-menus.php index f70826f..61b5a42 100644
switch ( $action ) { 343 343 344 344 if ( ! is_wp_error( $_menu_object ) ) { 345 345 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) ); 346 $nav_menu_id_changed = false; 347 if ( $nav_menu_selected_id != $_nav_menu_selected_id ) { 348 $nav_menu_selected_id = $_nav_menu_selected_id; 349 $nav_menu_id_changed = true; 350 } 351 346 352 if ( is_wp_error( $_nav_menu_selected_id ) ) { 347 353 $_menu_object = $_nav_menu_selected_id; 348 354 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; … … switch ( $action ) { 356 362 if ( ! is_wp_error( $_menu_object ) ) { 357 363 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) ); 358 364 } 365 366 // If the menu ID changed, redirect to the proper URL. 367 if ( $nav_menu_id_changed ) { 368 wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) ); 369 } 359 370 } 360 371 break; 361 372 case 'locations': -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index a1c9c97..46fafc1 100644
add_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 ); 330 330 // Split term updates. 331 331 add_action( 'split_shared_term', '_wp_check_split_default_terms', 10, 4 ); 332 332 add_action( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 ); 333 add_action( 'split_shared_term', '_wp_check_split_nav_menu_terms', 10, 4 ); 333 334 334 335 /** 335 336 * Filters formerly mixed into wp-includes -
src/wp-includes/nav-menu.php
diff --git src/wp-includes/nav-menu.php src/wp-includes/nav-menu.php index 29666f0..0163e90 100644
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { 311 311 $menu_id = (int) $_menu->term_id; 312 312 313 313 $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); 314 $menu_id = (int) $update_response['term_id']; 314 315 315 316 if ( is_wp_error( $update_response ) ) 316 317 return $update_response; -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index c2d0acc..8e3e03d 100644
function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_ 4396 4396 } 4397 4397 4398 4398 /** 4399 * If the term being split is a nav_menu, change associations. 4400 * 4401 * @ignore 4402 * @since 4.3.0 4403 * 4404 * @global wpdb $wpdb 4405 * 4406 * @param int $term_id ID of the formerly shared term. 4407 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. 4408 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. 4409 * @param string $taxonomy Taxonomy for the split term. 4410 */ 4411 function _wp_check_split_nav_menu_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 4412 if ( 'nav_menu' !== $taxonomy ) { 4413 return; 4414 } 4415 4416 // Update menu locations. 4417 $locations = get_nav_menu_locations(); 4418 foreach ( $locations as $location => $menu_id ) { 4419 if ( $term_id == $menu_id ) { 4420 $locations[ $location ] = $new_term_id; 4421 } 4422 } 4423 set_theme_mod( 'nav_menu_locations', $locations ); 4424 } 4425 4426 /** 4399 4427 * Get data about terms that previously shared a single term_id, but have since been split. 4400 4428 * 4401 4429 * @since 4.2.0 -
tests/phpunit/tests/term/splitSharedTerm.php
diff --git tests/phpunit/tests/term/splitSharedTerm.php tests/phpunit/tests/term/splitSharedTerm.php index 66fb8bc..b5439ef 100644
class Tests_Term_SplitSharedTerm extends WP_UnitTestCase { 195 195 $this->assertEquals( $new_term_id, get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 196 196 } 197 197 198 /** 199 * @ticket 33187 200 * @group navmenus 201 */ 202 public function test_nav_menu_locations_should_be_updated_on_split() { 203 global $wpdb; 204 205 $cat_term = wp_insert_term( 'Foo Menu', 'category' ); 206 $shared_term_id = $cat_term['term_id']; 207 208 $nav_term_id = wp_create_nav_menu( 'Foo Menu' ); 209 $nav_term = get_term( $nav_term_id, 'nav_menu' ); 210 211 // Manually modify because shared terms shouldn't naturally occur. 212 $wpdb->update( $wpdb->term_taxonomy, 213 array( 'term_id' => $shared_term_id ), 214 array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id ) 215 ); 216 217 set_theme_mod( 'nav_menu_locations', array( 'foo' => $shared_term_id ) ); 218 219 // Splitsville. 220 $new_term_id = _split_shared_term( $shared_term_id, $nav_term->term_taxonomy_id ); 221 222 $locations = get_nav_menu_locations(); 223 $this->assertEquals( $new_term_id, $locations['foo'] ); 224 } 225 226 /** 227 * @ticket 33187 228 * @group navmenus 229 */ 230 public function test_nav_menu_term_should_retain_menu_items_on_split() { 231 global $wpdb; 232 233 $cat_term = wp_insert_term( 'Foo Menu', 'category' ); 234 $shared_term_id = $cat_term['term_id']; 235 236 $nav_term_id = wp_create_nav_menu( 'Foo Menu' ); 237 $nav_term = get_term( $nav_term_id, 'nav_menu' ); 238 239 // Manually modify because shared terms shouldn't naturally occur. 240 $wpdb->update( $wpdb->term_taxonomy, 241 array( 'term_id' => $shared_term_id ), 242 array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id ) 243 ); 244 245 $t1 = wp_insert_term( 'Random term', 'category' ); 246 $cat_menu_item = wp_update_nav_menu_item( $shared_term_id, 0, array( 247 'menu-item-type' => 'taxonomy', 248 'menu-item-object' => 'category', 249 'menu-item-object-id' => $t1['term_id'], 250 'menu-item-status' => 'publish' 251 ) ); 252 253 // Updating the menu will split the shared term. 254 $new_nav_menu_id = wp_update_nav_menu_object( $shared_term_id, array( 255 'description' => 'Updated Foo Menu', 256 'menu-name' => 'Updated Foo Menu', 257 ) ); 258 259 $menu = wp_get_nav_menu_object( $new_nav_menu_id ); 260 $this->assertSame( 'Updated Foo Menu', $menu->name ); 261 $this->assertSame( 'Updated Foo Menu', $menu->description ); 262 263 $menu_items = wp_get_nav_menu_items( $new_nav_menu_id ); 264 $this->assertEquals( array( $cat_menu_item ), wp_list_pluck( $menu_items, 'ID' ) ); 265 } 266 198 267 public function test_wp_get_split_terms() { 199 268 $found = wp_get_split_terms( $this->terms['t1']['term_id'] ); 200 269