<?php
defined('WP_UNINSTALL_PLUGIN') || exit;

foreach ([
    'fixlinks_license_key', 'fixlinks_license_plan', 'fixlinks_license_gateway',
    'fixlinks_email_alerts', 'fixlinks_crawl_freq', 'fixlinks_last_crawl',
    'fixlinks_crawl_status', 'fixlinks_crawl_total', 'fixlinks_crawl_done',
    'fixlinks_db_version', 'fixlinks_pending_hits',
] as $opt) {
    delete_option($opt);
}
delete_transient('fixlinks_redirect_map');

$key = get_option('fixlinks_license_key', '');
if ($key) {
    wp_remote_get(
        add_query_arg(
            ['key' => $key, 'domain' => wp_parse_url( get_site_url(), PHP_URL_HOST ), 'action' => 'deactivate'],
            'https://fixlinks.getinfotoyou.com/validate-key.php'
        ),
        ['timeout' => 5]
    );
}

global $wpdb;
foreach (['fixlinks_broken', 'fixlinks_redirects', 'fixlinks_crawl_queue'] as $t) {
    $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}{$t}");
}

foreach ([
    'fixlinks_crawl_event', 'fixlinks_crawl_batch', 'fixlinks_weekly_email',
    'fixlinks_license_recheck', 'fixlinks_flush_hits',
] as $hook) {
    wp_clear_scheduled_hook($hook);
}