Getting this code to work in Multisite

The Problem:

When wp-cron.php is called, it includes only:

require_once( dirname( __FILE__ ) . '/wp-load.php' );

so the problem you are facing is that

wpmu_delete_blog()

is undefined when you call it from your remove_blogs_daily() function.

Possible Solution:

You therefore need to add this line:

require_once( ABSPATH . 'wp-admin/includes/admin.php' );

into your code to fix that.

Try this for example:

function remove_blogs_daily()
{ 
    require_once( ABSPATH . 'wp-admin/includes/admin.php' );

    if( ! function_exists( 'wpmu_delete_blog' ) ) return;

    $all_blogs = wp_get_sites();    

    $blogs_to_keep = array( 1, 2 );

    foreach ( $all_blogs as $key => $val )
    {
        if ( ! in_array( $val['blog_id'], $blogs_to_keep ) ) 
        {
            wpmu_delete_blog( $val['blog_id'], TRUE );          
        }
    }
}