Make WordPress Core

Ticket #26795: 26795.patch

File 26795.patch, 3.3 KB (added by ocean90, 12 years ago)
  • src/wp-includes/nav-menu.php

     
    702702        );
    703703        foreach( (array) $menu_items as $menu_item ) {
    704704                if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
    705                         if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) !== $object_type ||
    706                                 get_post_meta( $menu_item->ID, '_menu_item_object', true ) !== $taxonomy )
    707                                 continue;
    708 
    709                         $menu_item_ids[] = (int) $menu_item->ID;
     705                        $menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true );
     706                        if (
     707                                $object_type === 'post_type' &&
     708                                $menu_item_type === 'post_type'
     709                        ) {
     710                                $menu_item_ids[] = (int) $menu_item->ID;
     711                        } else if (
     712                                $object_type === 'taxonomy' &&
     713                                $menu_item_type === 'taxonomy' &&
     714                                get_post_meta( $menu_item->ID, '_menu_item_object', true ) === $taxonomy
     715                        ) {
     716                                $menu_item_ids[] = (int) $menu_item->ID;
     717                        }
    710718                }
    711719        }
    712720
  • tests/phpunit/tests/post/nav-menu.php

     
    1818        function test_wp_get_associated_nav_menu_items() {
    1919                $tag_id = $this->factory->tag->create();
    2020                $cat_id = $this->factory->category->create();
     21                $post_id = $this->factory->post->create();
     22                $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
    2123
    2224                $tag_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
    2325                        'menu-item-type' => 'taxonomy',
     
    3335                        'menu-item-status' => 'publish'
    3436                ) );
    3537
     38                $post_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
     39                        'menu-item-type' => 'post_type',
     40                        'menu-item-object' => 'post',
     41                        'menu-item-object-id' => $post_id,
     42                        'menu-item-status' => 'publish'
     43                ) );
     44
     45                $page_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
     46                        'menu-item-type' => 'post_type',
     47                        'menu-item-object' => 'page',
     48                        'menu-item-object-id' => $page_id,
     49                        'menu-item-status' => 'publish'
     50                ) );
     51
    3652                $tag_items = wp_get_associated_nav_menu_items( $tag_id, 'taxonomy', 'post_tag' );
    3753                $this->assertEqualSets( array( $tag_insert ), $tag_items );
    3854                $cat_items = wp_get_associated_nav_menu_items( $cat_id, 'taxonomy', 'category' );
    3955                $this->assertEqualSets( array( $cat_insert ), $cat_items );
     56                $post_items = wp_get_associated_nav_menu_items( $post_id );
     57                $this->assertEqualSets( array( $post_insert ), $post_items );
     58                $page_items = wp_get_associated_nav_menu_items( $page_id );
     59                $this->assertEqualSets( array( $page_insert ), $page_items );
     60
     61                wp_delete_term( $tag_id, 'post_tag' );
     62                $tag_items = wp_get_associated_nav_menu_items( $tag_id, 'taxonomy', 'post_tag' );
     63                $this->assertEqualSets( array(), $tag_items );
     64
     65                wp_delete_term( $cat_id, 'category' );
     66                $cat_items = wp_get_associated_nav_menu_items( $cat_id, 'taxonomy', 'category' );
     67                $this->assertEqualSets( array(), $cat_items );
     68
     69                wp_delete_post( $post_id, true );
     70                $post_items = wp_get_associated_nav_menu_items( $post_id );
     71                $this->assertEqualSets( array(), $post_items );
     72
     73                wp_delete_post( $page_id, true );
     74                $page_items = wp_get_associated_nav_menu_items( $page_id );
     75                $this->assertEqualSets( array(), $page_items );
    4076        }
    41 }
    42  No newline at end of file
     77}