diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 5bbcdfb44c..5ddfdcd3e3 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -231,8 +231,6 @@ add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); // Navigation menu actions -add_action( 'trash_post', '_wp_trash_menu_item' ); -add_action( 'untrash_post', '_wp_untrash_menu_item' ); add_action( 'delete_post', '_wp_delete_post_menu_item' ); add_action( 'delete_term', '_wp_delete_tax_menu_item' ); add_action( 'transition_post_status', '_wp_menu_changing_status_observer', 10, 3 ); diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 5efd41888f..5cb7d1cb3c 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -311,9 +311,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $original_object = get_post( $args['menu-item-object-id'] ); $original_parent = (int) $original_object->post_parent; $original_title = $original_object->post_title; - - if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) - 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'] ) ); } if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) { @@ -654,48 +651,6 @@ function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_ return array_unique( $menu_item_ids ); } -/** - * Callback for handling a menu item when its original object is trashed. - * - * @since 3.0.0 - * @access private - * - * @param int $object_id The ID of the original object being trashed. - * - */ -function _wp_trash_menu_item( $object_id = 0 ) { - $object_id = (int) $object_id; - - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); - - foreach( (array) $menu_item_ids as $menu_item_id ) { - $menu_item = get_post( $menu_item_id, ARRAY_A ); - $menu_item['post_status'] = 'pending'; - wp_insert_post($menu_item); - } -} - -/** - * Callback for handling a menu item when its original object is un-trashed. - * - * @since 3.0.0 - * @access private - * - * @param int $object_id The ID of the original object being untrashed. - * - */ -function _wp_untrash_menu_item( $object_id = 0 ) { - $object_id = (int) $object_id; - - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id ); - - foreach( (array) $menu_item_ids as $menu_item_id ) { - $menu_item = get_post( $menu_item_id, ARRAY_A ); - $menu_item['post_status'] = 'publish'; - wp_insert_post($menu_item); - } -} - /** * Callback for handling a menu item when its original object is deleted. * @@ -780,11 +735,10 @@ function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) { // give menu items draft status if their associated post objects change from "publish" to "draft", or vice versa (draft item being re-published) if ( - ! empty( $post->ID ) && - ( - ( 'publish' == $old_status && 'draft' == $new_status ) || - ( 'draft' == $old_status && 'publish' == $new_status ) - ) + ( $new_status != $old_status ) && + ! empty( $post->ID ) && ! empty( $post->post_type ) && + 'nav_menu_item' != $post->post_type && + ( 'publish' == $old_status || 'publish' == $new_status ) ) { $menu_items = get_posts(array( 'meta_key' => '_menu_item_object_id', @@ -796,7 +750,7 @@ function _wp_menu_changing_status_observer( $new_status, $old_status, $post ) { foreach( (array) $menu_items as $menu_item ) { if ( ! empty( $menu_item->ID ) ) { $properties = get_object_vars( $menu_item ); - $properties['post_status'] = $new_status; + $properties['post_status'] = 'publish' == $new_status ? 'publish' : 'draft'; wp_insert_post( $properties ); }