$classic_nav_menu_blocks = WP_Classic_To_Block_Menu_Converter::
convert( $classic_nav_menu );
if ( is_wp_error( $classic_nav_menu_blocks ) ) { return $classic_nav_menu_blocks;
} if ( empty( $classic_nav_menu_blocks ) ) { return new WP_Error( 'cannot_convert_classic_menu',
__( 'Unable to convert Classic Menu to blocks.'
) );
} // Create a new navigation menu from the classic menu.
$classic_menu_fallback =
wp_insert_post( array
( 'post_content' =>
$classic_nav_menu_blocks,
'post_title' =>
$classic_nav_menu->name,
'post_name' =>
$classic_nav_menu->slug,
'post_status' => 'publish',
'post_type' => 'wp_navigation',
),
true // So that we can check whether the result is an error.
);
return $classic_menu_fallback;
}