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.

git-svn-id: https://develop.svn.wordpress.org/trunk@27150 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2014-02-09 21:36:15 +00:00
parent d670819b03
commit 586cb2b140
2 changed files with 64 additions and 6 deletions
+13 -5
View File
@@ -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;
}
}
}