From 31d1f909a4d16ba8e6a1df60956e4ddc4a5f6f22 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Sun, 9 Feb 2014 21:37:11 +0000 Subject: [PATCH] Nav Menu: Remove post/page items from the Nav Menu when the post/page is deleted. This was broken through a change in [25163]. `_menu_item_object` in wp_get_associated_nav_menu_items() is not relevant for post types. Adds unit tests. props UmeshSingla for initial patch. fixes #26795. Built from https://develop.svn.wordpress.org/trunk@27150 git-svn-id: http://core.svn.wordpress.org/trunk@27017 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index cf9ac1427e..af69dfc897 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -702,11 +702,19 @@ function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_ ); foreach( (array) $menu_items as $menu_item ) { if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { - if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) !== $object_type || - get_post_meta( $menu_item->ID, '_menu_item_object', true ) !== $taxonomy ) - continue; - - $menu_item_ids[] = (int) $menu_item->ID; + $menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); + if ( + 'post_type' == $object_type && + 'post_type' == $menu_item_type + ) { + $menu_item_ids[] = (int) $menu_item->ID; + } else if ( + 'taxonomy' == $object_type && + 'taxonomy' == $menu_item_type && + get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy + ) { + $menu_item_ids[] = (int) $menu_item->ID; + } } }