i’ve done a routine upgrade of wordpress 4.1.x to 4.2 and later 4.2.1. all seemed fine until the day i wanted to manually adjust the menu structure using wp-admin > appearance > menus. each attempt of saving my menu resulted in it being wiped out completely
i’ve started digging into the code and found out that commenting in wp-admin/nav-menus.php:
$_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
would prevent the problem
then deeper into the rabbit’s hole: wp-includes/nav-menu.php
$update_response = wp_update_term( $menu_id, 'nav_menu', $args );
$_term_id = _split_shared_term( $term_id, $tt_id );
so – we’re onto something. google gave me: https://developer.wordpress.org/plugins/taxonomy/working-with-split-terms-in-wp-4-2/ which mentions splitting of the terms shared for different taxonomies. hm… what do we have in the wp_term_taxonomy table? oh.. two entries with the same term_id: one with taxonomy=nav_menu, another with taxonomy=category. apparently ages ago i’ve created a category called also top menu, it wasn’t used anywhere but its mere presence was enough to trigger the problem. i went to wp-admin > posts > categories and deleted the an entry top menu. after that i was able to save the menu without hassle again!
i’ve tried to reproduce this problem on a clean installation of 4.1.4 with the same menu name as category name then upgraded to 4.2.1 but I could not. most probably it’s some database inconsistency that we’ve been carrying for a longer time from the earlier versions of wp [initially we’ve started on 3.9.x then 4.0.x, 4.1.x and 4.2.x]. so it’s not something i can easily report to the wordpress devs. hopefully this entry helps someone encountering similar problem.