WordPress.org

Make WordPress Core

Ticket #34803: 34803.diff

File 34803.diff, 1.1 KB (added by shooper, 5 years ago)

Reassign child nav menu items to the grandparent before deleting a nav-menu-item post.

  • src/wp-includes/post.php

     
    24092409                $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
    24102410        }
    24112411
     2412        if ( $post->post_type == 'nav_menu_item') {
     2413                // Get this menu item's parent
     2414                $parent_menu_id = (int)get_post_meta ( $post->ID, '_menu_item_menu_item_parent', true );
     2415
     2416                // Move all children of this nav menu to the parent
     2417                $children_query = $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %d WHERE meta_key = '_menu_item_menu_item_parent' AND meta_value=%s", $parent_menu_id, $post->ID);
     2418                $children = $wpdb->query ( $children_query );
     2419        }
     2420
    24122421        // Do raw query. wp_get_post_revisions() is filtered.
    24132422        $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    24142423        // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.