alt-magic-ai-powered-alt-texts
Last commit date
admin-functions
5 months ago
admin-settings-pages
5 months ago
assets
5 months ago
common-functions
5 months ago
css
5 months ago
integrations-functions
5 months ago
media-library-page-functions
5 months ago
scripts
5 months ago
altm-main-file.php
5 months ago
index.php
5 months ago
readme.txt
5 months ago
uninstall.php
5 months ago
uninstall.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | // Ensure this file is not accessed directly |
| 4 | if (!defined('WP_UNINSTALL_PLUGIN')) { |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | // Include the main plugin file to get constants |
| 9 | require_once dirname(__FILE__) . '/altm-main-file.php'; |
| 10 | |
| 11 | // Define the server endpoint for plugin events |
| 12 | define('ALT_MAGIC_PLUGIN_EVENTS_ENDPOINT', '/wp-plugin-events'); |
| 13 | |
| 14 | /** |
| 15 | * Send plugin deletion event ping to server |
| 16 | * This function is called when the plugin is deleted (uninstalled) |
| 17 | */ |
| 18 | function altm_send_plugin_deletion_ping() { |
| 19 | // Get site information |
| 20 | $site_url = get_site_url(); |
| 21 | |
| 22 | // Get user_id if available |
| 23 | $user_id = get_option('alt_magic_user_id'); |
| 24 | |
| 25 | // Prepare the request data (trimmed to essential fields only) |
| 26 | $request_data = array( |
| 27 | 'event_type' => 'deleted', |
| 28 | 'plugin_version' => ALT_MAGIC_PLUGIN_VERSION, |
| 29 | 'site_url' => $site_url |
| 30 | ); |
| 31 | |
| 32 | // Add user_id if available |
| 33 | if (!empty($user_id)) { |
| 34 | $request_data['user_id'] = $user_id; |
| 35 | } |
| 36 | |
| 37 | // Get the base URL for the ping |
| 38 | $base_url = ALT_MAGIC_API_BASE_URL; |
| 39 | $ping_url = $base_url . ALT_MAGIC_PLUGIN_EVENTS_ENDPOINT; |
| 40 | |
| 41 | // Prepare the request arguments |
| 42 | $args = array( |
| 43 | 'method' => 'POST', |
| 44 | 'headers' => array( |
| 45 | 'Content-Type' => 'application/json', |
| 46 | 'User-Agent' => 'Alt-Magic-WordPress-Plugin/' . ALT_MAGIC_PLUGIN_VERSION |
| 47 | ), |
| 48 | 'body' => wp_json_encode($request_data), |
| 49 | 'timeout' => 30, |
| 50 | 'blocking' => false, // Non-blocking request to avoid slowing down uninstall |
| 51 | 'httpversion' => '1.1', |
| 52 | 'sslverify' => true |
| 53 | ); |
| 54 | |
| 55 | // Send the ping |
| 56 | $response = wp_remote_post($ping_url, $args); |
| 57 | |
| 58 | if (is_wp_error($response)) { |
| 59 | // Log error if possible (though logging might not be available during uninstall) |
| 60 | altm_log('Alt Magic: Failed to send plugin deletion ping: ' . $response->get_error_message()); |
| 61 | } else { |
| 62 | $response_code = wp_remote_retrieve_response_code($response); |
| 63 | if ($response_code >= 200 && $response_code < 300) { |
| 64 | altm_log('Alt Magic: Successfully sent plugin deletion ping'); |
| 65 | } else { |
| 66 | altm_log('Alt Magic: Plugin deletion ping returned status code: ' . $response_code); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // Send the deletion ping |
| 72 | altm_send_plugin_deletion_ping(); |
| 73 | |
| 74 | // Clean up plugin options (optional - uncomment if you want to remove all plugin data) |
| 75 | /* |
| 76 | $options_to_remove = [ |
| 77 | 'alt_magic_account_active', |
| 78 | 'alt_magic_api_key', |
| 79 | 'alt_magic_user_id', |
| 80 | 'alt_magic_language', |
| 81 | 'alt_magic_use_for_title', |
| 82 | 'alt_magic_use_for_caption', |
| 83 | 'alt_magic_use_for_description', |
| 84 | 'alt_magic_prepend_string', |
| 85 | 'alt_magic_append_string', |
| 86 | 'alt_magic_auto_generate', |
| 87 | 'alt_magic_auto_rename_on_upload', |
| 88 | 'alt_magic_use_seo_keywords', |
| 89 | 'alt_magic_use_post_title', |
| 90 | 'alt_magic_refresh_alt_text', |
| 91 | 'alt_magic_private_site', |
| 92 | 'alt_magic_woocommerce_use_product_name', |
| 93 | 'alt_magic_rename_use_seo_keywords', |
| 94 | 'alt_magic_rename_use_post_title', |
| 95 | 'alt_magic_rename_use_woocommerce_product_name', |
| 96 | 'alt_magic_max_concurrency' |
| 97 | ]; |
| 98 | |
| 99 | foreach ($options_to_remove as $option) { |
| 100 | delete_option($option); |
| 101 | } |
| 102 | */ |
| 103 | |
| 104 | ?> |
| 105 |