Make WordPress Core

Changeset 25163


Ignore:
Timestamp:
08/29/2013 04:44:36 PM (11 years ago)
Author:
wonderboymusic
Message:

Pass the taxonomy around to relevant nav menu actions to avoid arbitrarily deleting all items with menu-item-type of taxonomy. Adds unit test for wp_get_associated_nav_menu_items().

Props garyc40, SergeyBiryukov.
Fixes #15264.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r25134 r25163  
    263263// Navigation menu actions
    264264add_action( 'delete_post',                '_wp_delete_post_menu_item'         );
    265 add_action( 'delete_term',                '_wp_delete_tax_menu_item'          );
     265add_action( 'delete_term',                '_wp_delete_tax_menu_item',   10, 3 );
    266266add_action( 'transition_post_status',     '_wp_auto_add_pages_to_menu', 10, 3 );
    267267
  • trunk/src/wp-includes/nav-menu.php

    r24560 r25163  
    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();
     
    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
     
    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 ) {
Note: See TracChangeset for help on using the changeset viewer.