[wp-trac] [WordPress Trac] #15264: Deleting a term shared across taxonomies deletes all associated nav menus.

WordPress Trac wp-trac at lists.automattic.com
Sat Nov 6 10:30:10 UTC 2010


#15264: Deleting a term shared across taxonomies deletes all associated nav menus.
--------------------------+-------------------------------------------------
 Reporter:  michelwppi    |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Taxonomy      |     Version:  3.0.1          
 Severity:  major         |    Keywords:  needs-patch    
--------------------------+-------------------------------------------------

Comment(by michelwppi):

 After one week of tests and understanding complex data-model of menu-items
 in posts table, I suggest these light modifications :
 1) in default-filters.php (around line 235) - params were omitted


 {{{
 //add_action( 'delete_term',                '_wp_delete_tax_menu_item'
 );
 add_action( 'delete_term',                '_wp_delete_tax_menu_item', 10,
 3 );
 }}}


 2) in nav-menu.php : only menu item type taxonomy with the same content
 (currently category) can be deleted - so a post_tag deleted don't destroy
 a menu item based on category with same name of post_tag (or other
 taxonomies)

 {{{
 /**
  * Callback for handling a menu item when its original object is deleted.
  *
  * @since 3.0.0
  * @access private
  *
  * @param int $object_id The ID of the original object being trashed AND
 taxonomy passed form wp_delete_term
  *
  */
 function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
 //2 params added (see taxonomy wp_delete_term and default-filters)
         $object_id = (int) $object_id;

         // $menu_item_ids = wp_get_associated_nav_menu_items( $object_id,
 'taxonomy' );

         $menu_item_ids = array();

         $query = new WP_Query;
         $menu_items = $query->query(
                 array(
                         'meta_key' => '_menu_item_object_id',
                         'meta_value' => $object_id,
                         'post_status' => 'any',
                         'post_type' => 'nav_menu_item',
                         'showposts' => -1,
                 )
         );
         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 ) != 'taxonomy' )
                                 continue;
                         if ( get_post_meta( $menu_item->ID,
 '_menu_item_object', true ) != $taxonomy ) // only if corresponding #15264
                                 continue;
                         $menu_item_ids[] = (int) $menu_item->ID;
                 }
         }
         $menu_item_ids = array_unique( $menu_item_ids );

         foreach( (array) $menu_item_ids as $menu_item_id ) {
                 wp_delete_post( $menu_item_id, true );
         }
 }


 }}}

 Hope it is helpfull

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15264#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list