<?php
if ( ! defined('WP_UNINSTALL_PLUGIN') ) exit;

function uem_delete_site_data() {
    global $wpdb;
    foreach (['upcoming_events_%','uem_%','_transient_uem_%','_transient_timeout_uem_%'] as $like) {
        $names = $wpdb->get_col( $wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", $like) );
        foreach ($names as $opt) delete_option($opt);
    }
    $ids = get_posts(['post_type'=>'upcoming_event','numberposts'=>-1,'fields'=>'ids','post_status'=>'any']);
    foreach ($ids as $id) wp_delete_post($id, true);
}

if ( is_multisite() ) {
    $sites = get_sites(['fields'=>'ids']);
    foreach ($sites as $blog_id) {
        switch_to_blog($blog_id);
        uem_delete_site_data();
        restore_current_blog();
    }
} else {
    uem_delete_site_data();
}