Make WordPress Core

Ticket #13822: 13822.logic.and.trash.diff

File 13822.logic.and.trash.diff, 3.6 KB (added by koopersmith, 15 years ago)
  • wp-includes/default-filters.php

     
    231231add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'            );
    232232
    233233// Navigation menu actions
    234 add_action( 'trash_post',                 '_wp_trash_menu_item'            );
    235 add_action( 'untrash_post',               '_wp_untrash_menu_item'          );
    236234add_action( 'delete_post',                '_wp_delete_post_menu_item'      );
    237235add_action( 'delete_term',                '_wp_delete_tax_menu_item'       );
    238236add_action( 'transition_post_status', '_wp_menu_changing_status_observer',  10, 3 );
  • wp-includes/nav-menu.php

     
    311311                        $original_object = get_post( $args['menu-item-object-id'] );
    312312                        $original_parent = (int) $original_object->post_parent;
    313313                        $original_title = $original_object->post_title;
    314 
    315                         if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) )
    316                                 return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to something that is in the trash, so it cannot be updated.'), $args['menu-item-title'] ) );
    317314                }
    318315
    319316                if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) {
     
    655652}
    656653
    657654/**
    658  * Callback for handling a menu item when its original object is trashed.
    659  *
    660  * @since 3.0.0
    661  * @access private
    662  *
    663  * @param int $object_id The ID of the original object being trashed.
    664  *
    665  */
    666 function _wp_trash_menu_item( $object_id = 0 ) {
    667         $object_id = (int) $object_id;
    668 
    669         $menu_item_ids = wp_get_associated_nav_menu_items( $object_id );
    670 
    671         foreach( (array) $menu_item_ids as $menu_item_id ) {
    672                 $menu_item = get_post( $menu_item_id, ARRAY_A );
    673                 $menu_item['post_status'] = 'pending';
    674                 wp_insert_post($menu_item);
    675         }
    676 }
    677 
    678 /**
    679  * Callback for handling a menu item when its original object is un-trashed.
    680  *
    681  * @since 3.0.0
    682  * @access private
    683  *
    684  * @param int $object_id The ID of the original object being untrashed.
    685  *
    686  */
    687 function _wp_untrash_menu_item( $object_id = 0 ) {
    688         $object_id = (int) $object_id;
    689 
    690         $menu_item_ids = wp_get_associated_nav_menu_items( $object_id );
    691 
    692         foreach( (array) $menu_item_ids as $menu_item_id ) {
    693                 $menu_item = get_post( $menu_item_id, ARRAY_A );
    694                 $menu_item['post_status'] = 'publish';
    695                 wp_insert_post($menu_item);
    696         }
    697 }
    698 
    699 /**
    700655 * Callback for handling a menu item when its original object is deleted.
    701656 *
    702657 * @since 3.0.0
     
    780735
    781736        // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published)
    782737        if (
    783                 ! empty( $post->ID ) &&
    784                 (
    785                         ( 'publish' == $old_status && 'draft' == $new_status ) ||
    786                         ( 'draft' == $old_status && 'publish' == $new_status )
    787                 )
     738                ( $new_status != $old_status ) &&
     739                ! empty( $post->ID ) && ! empty( $post->post_type ) &&
     740                'nav_menu_item' != $post->post_type &&
     741                ( 'publish' == $old_status || 'publish' == $new_status )
    788742        ) {
    789743                $menu_items = get_posts(array(
    790744                        'meta_key' => '_menu_item_object_id',
     
    796750                foreach( (array) $menu_items as $menu_item ) {
    797751                        if ( ! empty( $menu_item->ID ) ) {
    798752                                $properties = get_object_vars( $menu_item );
    799                                 $properties['post_status'] = $new_status;
     753                                $properties['post_status'] = 'publish' == $new_status ? 'publish' : 'draft';
    800754
    801755                                wp_insert_post( $properties );
    802756                        }