When splitting a shared 'nav_menu' term, ensure that nav items and theme locations are retained.

Props boonebgorges, dd32.
Fixes #33187.
Built from https://develop.svn.wordpress.org/trunk@33611


git-svn-id: http://core.svn.wordpress.org/trunk@33578 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-08-12 14:07:26 +00:00
parent 7fcc3e50e1
commit 2c9e81349c
5 changed files with 39 additions and 2 deletions

View File

@ -354,7 +354,13 @@ switch ( $action ) {
// Update menu items.
if ( ! is_wp_error( $_menu_object ) ) {
$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) );
$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
// If the menu ID changed, redirect to the new URL.
if ( $nav_menu_selected_id != $_nav_menu_selected_id ) {
wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) );
exit();
}
}
}
break;

View File

@ -330,6 +330,7 @@ add_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 );
// Split term updates.
add_action( 'split_shared_term', '_wp_check_split_default_terms', 10, 4 );
add_action( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 );
add_action( 'split_shared_term', '_wp_check_split_nav_menu_terms', 10, 4 );
/**
* Filters formerly mixed into wp-includes

View File

@ -315,6 +315,8 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
if ( is_wp_error( $update_response ) )
return $update_response;
$menu_id = (int) $update_response['term_id'];
/**
* Fires after a navigation menu has been successfully updated.
*

View File

@ -4395,6 +4395,34 @@ function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_
}
}
/**
* If the term being split is a nav_menu, change associations.
*
* @ignore
* @since 4.3.0
*
* @global wpdb $wpdb
*
* @param int $term_id ID of the formerly shared term.
* @param int $new_term_id ID of the new term created for the $term_taxonomy_id.
* @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split.
* @param string $taxonomy Taxonomy for the split term.
*/
function _wp_check_split_nav_menu_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
if ( 'nav_menu' !== $taxonomy ) {
return;
}
// Update menu locations.
$locations = get_nav_menu_locations();
foreach ( $locations as $location => $menu_id ) {
if ( $term_id == $menu_id ) {
$locations[ $location ] = $new_term_id;
}
}
set_theme_mod( 'nav_menu_locations', $locations );
}
/**
* Get data about terms that previously shared a single term_id, but have since been split.
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-RC2-33610';
$wp_version = '4.3-RC2-33611';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.