Editing existing pre-created menus in PHP

I’ve found a solution to my problem by going over the documentation again and again, looking through source files and just generally running the same section of code over and over to scrutinize the output.

This is the solution I came up with, which works just perfectly for my needs:

//  Get a list of all the menus that are part of the site
    $menu_list = wp_get_nav_menus();
    $menu_id = -1;
//  Iterate over all the menus...
    foreach( $menu_list as $menu ) {
    //  ...and find the one you want...
        if( $menu->name === 'Main Menu' ) {
        //  ...and get it's ID.
            $menu_id = $menu->term_id;
        }
    }

//  Delete everything except the Home entry
    $menu_content = wp_get_nav_menu_items( 'Main Menu' );
    foreach( $menu_content as $menu_item ) {
        if($menu_item->title !== 'Home') {
            wp_delete_post($menu_item->ID);
        }
    }

   /* OTHER CODE USED FOR BUILDING PAGES, ETC CODE */

   /**
    *   Menu building code
    *
    *   @since 0.4.0pre1
    */
    $menu_data = array(
                        'menu-item-title' => ( $menu_text !== '' ) ? wp_strip_all_tags( $menu_text ) : wp_strip_all_tags( $page_title ),
                        'menu-item-object' => 'page',
                        'menu-item-parent-id' => ( $parent !== '' || $parent !== 'none' ) ? intval( $parent ) : 0,
                        'menu-item-position'  => ( $menu_position !== '' ) ? ( intval( $menu_position ) === 1 ? 2 : intval( $menu_position ) ): 2,
                        'menu-item-object-id' => $post_id,
                        'menu-item-type' => 'post_type',
                        'menu-item-status' => 'publish'
                     );

//  Add this menu item to the existing nav menu if it is set to visible
    if( intval( $menu_visible ) !== false ) {
        wp_update_nav_menu_item( $menu_id, 0, $menu_data );
    }

Feel free to suggest any improvements to the code, or any other suggestions 🙂

tech