Make WordPress Core

Ticket #15264: 15264.4.diff

File 15264.4.diff, 3.7 KB (added by wonderboymusic, 11 years ago)
  • tests/tests/post/nav-menu.php

     
     1<?php
     2/**
     3 * @group post
     4 * @group navmenus
     5 */
     6class Test_Nav_Menus extends WP_UnitTestCase {
     7        /**
     8         * @var int
     9         */
     10        public $menu_id;
     11
     12        function setUp() {
     13                parent::setUp();
     14
     15                $this->menu_id = wp_create_nav_menu( rand_str() );
     16        }
     17
     18        function test_wp_get_associated_nav_menu_items() {
     19                $tag_id = $this->factory->tag->create();
     20                $cat_id = $this->factory->category->create();
     21
     22                $tag_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
     23                        'menu-item-type' => 'taxonomy',
     24                        'menu-item-object' => 'post_tag',
     25                        'menu-item-object-id' => $tag_id,
     26                        'menu-item-status' => 'publish'
     27                ) );
     28
     29                $cat_insert = wp_update_nav_menu_item( $this->menu_id, 0, array(
     30                        'menu-item-type' => 'taxonomy',
     31                        'menu-item-object' => 'category',
     32                        'menu-item-object-id' => $cat_id,
     33                        'menu-item-status' => 'publish'
     34                ) );
     35
     36                $tag_items = wp_get_associated_nav_menu_items( $tag_id, 'taxonomy', 'post_tag' );
     37                $this->assertEqualSets( array( $tag_insert ), $tag_items );
     38                $cat_items = wp_get_associated_nav_menu_items( $cat_id, 'taxonomy', 'category' );
     39                $this->assertEqualSets( array( $cat_insert ), $cat_items );
     40        }
     41}
  • src/wp-includes/default-filters.php

     
    266266
    267267// Navigation menu actions
    268268add_action( 'delete_post',                '_wp_delete_post_menu_item'         );
    269 add_action( 'delete_term',                '_wp_delete_tax_menu_item'          );
     269add_action( 'delete_term',                '_wp_delete_tax_menu_item',   10, 3 );
    270270add_action( 'transition_post_status',     '_wp_auto_add_pages_to_menu', 10, 3 );
    271271
    272272// Post Thumbnail CSS class filtering
  • src/wp-includes/nav-menu.php

     
    685685 *
    686686 * @param int $object_id The ID of the original object.
    687687 * @param string $object_type The type of object, such as "taxonomy" or "post_type."
     688 * @param string $taxonomy If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to
    688689 * @return array The array of menu item IDs; empty array if none;
    689690 */
    690 function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) {
     691function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) {
    691692        $object_id = (int) $object_id;
    692693        $menu_item_ids = array();
    693694
     
    703704        );
    704705        foreach( (array) $menu_items as $menu_item ) {
    705706                if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
    706                         if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) != $object_type )
     707                        if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) !== $object_type ||
     708                                get_post_meta( $menu_item->ID, '_menu_item_object', true ) !== $taxonomy )
    707709                                continue;
    708710
    709711                        $menu_item_ids[] = (int) $menu_item->ID;
     
    741743 * @param int $object_id The ID of the original object being trashed.
    742744 *
    743745 */
    744 function _wp_delete_tax_menu_item( $object_id = 0 ) {
     746function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
    745747        $object_id = (int) $object_id;
    746748
    747         $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy' );
     749        $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );
    748750
    749751        foreach( (array) $menu_item_ids as $menu_item_id ) {
    750752                wp_delete_post( $menu_item_id, true );