Make WordPress Core

Changeset 15249


Ignore:
Timestamp:
06/14/2010 08:33:48 AM (15 years ago)
Author:
nacin
Message:

Treat trash/untrash of posts associated with media items the same as other stati changes. props koopersmith, see #13822.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r15219 r15249  
    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'       );
  • trunk/wp-includes/nav-menu.php

    r15235 r15249  
    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
     
    653650
    654651    return array_unique( $menu_item_ids );
    655 }
    656 
    657 /**
    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     }
    697652}
    698653
     
    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(
     
    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 );
Note: See TracChangeset for help on using the changeset viewer.