WordPress.org

Make WordPress Core

Ticket #29728: wp_delete_nav_menu_item.patch

File wp_delete_nav_menu_item.patch, 2.9 KB (added by tyxla, 6 years ago)

Implementation of wp_delete_nav_menu_item() and its usage in the core, as described in my last reply.

  • wp-admin/includes/nav-menu.php

     
    12371237        $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
    12381238
    12391239        foreach( (array) $menu_items_to_delete as $menu_item_id )
    1240                 wp_delete_post( $menu_item_id, true );
     1240                wp_delete_nav_menu_item( $menu_item_id );
    12411241}
    12421242add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
    12431243
     
    12911291        if ( ! empty( $menu_items ) ) {
    12921292                foreach ( array_keys( $menu_items ) as $menu_item_id ) {
    12931293                        if ( is_nav_menu_item( $menu_item_id ) ) {
    1294                                 wp_delete_post( $menu_item_id );
     1294                                wp_delete_nav_menu_item( $menu_item_id );
    12951295                        }
    12961296                }
    12971297        }
  • wp-admin/nav-menus.php

     
    230230
    231231                check_admin_referer( 'delete-menu_item_' . $menu_item_id );
    232232
    233                 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )
     233                if ( wp_delete_nav_menu_item( $menu_item_id ) )
    234234                        $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';
    235235                break;
    236236
  • wp-includes/nav-menu.php

     
    187187        $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
    188188        if ( ! empty( $menu_objects ) ) {
    189189                foreach ( $menu_objects as $item ) {
    190                         wp_delete_post( $item );
     190                        wp_delete_nav_menu_item( $item );
    191191                }
    192192        }
    193193
     
    453453}
    454454
    455455/**
     456 * Delete a menu item.
     457 *
     458 * @param int $menu_item_id The ID of the menu item. Required.
     459 * @return bool $result         True if deletion was successful, false otherwise.
     460 */
     461function wp_delete_nav_menu_item( $menu_item_id ) {
     462    $result = is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true );
     463    return $result;
     464}
     465
     466/**
    456467 * Returns all navigation menu objects.
    457468 *
    458469 * @since 3.0.0
     
    834845        $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' );
    835846
    836847        foreach( (array) $menu_item_ids as $menu_item_id ) {
    837                 wp_delete_post( $menu_item_id, true );
     848                wp_delete_nav_menu_item( $menu_item_id );
    838849        }
    839850}
    840851
     
    853864        $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );
    854865
    855866        foreach( (array) $menu_item_ids as $menu_item_id ) {
    856                 wp_delete_post( $menu_item_id, true );
     867                wp_delete_nav_menu_item( $menu_item_id );
    857868        }
    858869}
    859870