<?php

if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
} function puffergo_uninstall_telemetry_base_url()
{
    return defined('PUFFERGO_AI_PAGE_BUILDER_BASE_URL') ? PUFFERGO_AI_PAGE_BUILDER_BASE_URL : 'https://api.puffergo.com';
} function puffergo_send_uninstall_telemetry()
{
    $reason = get_option('puffergo_uninstall_reason', '');
    $detail = get_option('puffergo_uninstall_reason_detail', '');
    $base = puffergo_uninstall_telemetry_base_url();
    $payload = array('eventType' => 'uninstall', 'domain' => home_url(), 'phpVersion' => PHP_VERSION, 'wpVersion' => (isset($GLOBALS['wp_version']) && is_string($GLOBALS['wp_version'])) ? $GLOBALS['wp_version'] : '', 'pufferGoVersion' => get_option('puffergo_version', ''), 'uninstallReason' => is_string($reason) ? $reason : '', 'uninstallReasonDetail' => is_string($detail) ? $detail : '', );
    wp_remote_post($base . '/api/telemetry/event', array('headers' => array('Content-Type' => 'application/json; charset=utf-8'), 'body' => wp_json_encode($payload), 'timeout' => 3, ));
} function puffergo_delete_options()
{
    delete_option('puffergo_api_key');
    delete_option('puffergo_settings');
    delete_option('puffergo_version');
    delete_option('puffergo_uninstall_reason');
    delete_option('puffergo_uninstall_reason_detail');
    delete_option('puffergo_download_sent');
    delete_option('puffergo_sample_data_imported');

    if (is_multisite()) {
        delete_site_option('puffergo_api_key');
        delete_site_option('puffergo_settings');
        delete_site_option('puffergo_version');
        delete_site_option('puffergo_uninstall_reason');
        delete_site_option('puffergo_uninstall_reason_detail');
        delete_site_option('puffergo_download_sent');
        delete_site_option('puffergo_sample_data_imported');
    }
} function puffergo_delete_transients()
{
    global $wpdb;
    $wpdb->query("DELETE FROM {$wpdb->options} 
        WHERE option_name LIKE '_transient_puffergo_%' 
        OR option_name LIKE '_transient_timeout_puffergo_%'");

    if (is_multisite()) {
        $wpdb->query("DELETE FROM {$wpdb->sitemeta} 
            WHERE meta_key LIKE '_site_transient_puffergo_%' 
            OR meta_key LIKE '_site_transient_timeout_puffergo_%'");
    }
} function puffergo_uninstall()
{
    puffergo_send_uninstall_telemetry();
    puffergo_delete_options();
    puffergo_delete_transients();
} puffergo_uninstall();

if (defined('WP_DEBUG') && WP_DEBUG) {
    error_log('PufferGo: 插件已卸载,所有数据已清理');
}
