mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
When splitting a shared 'nav_menu' term, ensure that nav items and theme locations are retained.
Props boonebgorges, dd32. Fixes #33187. git-svn-id: https://develop.svn.wordpress.org/trunk@33611 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user