Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
137 lines (117 loc) · 6.12 KB
/
Copy pathuninstall.php
File metadata and controls
137 lines (117 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* WebDecoy Plugin Uninstall
*
* Fired when the plugin is uninstalled.
* Cleans up all plugin data including database tables, options, and transients.
*
* @package WebDecoy
*/
// If uninstall not called from WordPress, exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
global $wpdb;
// Load the activator class if not already loaded
$activator_file = __DIR__ . '/includes/class-webdecoy-activator.php';
if (file_exists($activator_file)) {
require_once $activator_file;
// Use the uninstall method if available
if (class_exists('WebDecoy_Activator') && method_exists('WebDecoy_Activator', 'uninstall')) {
WebDecoy_Activator::uninstall();
}
} else {
// Fallback: manually clean up if activator not available
// Drop custom tables
$tables = [
$wpdb->prefix . 'webdecoy_blocked_ips',
$wpdb->prefix . 'webdecoy_detections',
$wpdb->prefix . 'webdecoy_rate_limits',
$wpdb->prefix . 'webdecoy_checkout_attempts',
$wpdb->prefix . 'webdecoy_ai_referrals',
$wpdb->prefix . 'webdecoy_request_counts',
$wpdb->prefix . 'webdecoy_crawler_visits',
$wpdb->prefix . 'webdecoy_ai_referral_days',
];
foreach ($tables as $table) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name is safe, built from $wpdb->prefix
$wpdb->query("DROP TABLE IF EXISTS {$table}");
}
// Delete plugin options
delete_option('webdecoy_options');
delete_option('webdecoy_db_version');
delete_option('webdecoy_request_counts_started_at');
delete_option('webdecoy_api_status');
delete_option('webdecoy_api_last_check');
delete_option('webdecoy_api_last_error');
delete_option('webdecoy_encryption_key');
delete_option('webdecoy_entitlements');
delete_option('webdecoy_cloud_policy');
delete_option('webdecoy_actor_feed_cursor');
delete_option('webdecoy_critical_moment_last');
// Clear scheduled events
wp_clear_scheduled_hook('webdecoy_cleanup_expired');
wp_clear_scheduled_hook('webdecoy_sync_blocked_ips');
wp_clear_scheduled_hook('webdecoy_sync_entitlements');
wp_clear_scheduled_hook('webdecoy_sync_actor_feed');
wp_clear_scheduled_hook('webdecoy_flush_ai_referrals');
}
// Delete all transients with webdecoy_ prefix
// Delete transients from options table
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Explicit uninstall cleanup of plugin-owned tables/transients; mutation cannot use a cached result.
$wpdb->query(
$wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_webdecoy_') . '%')
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Explicit uninstall cleanup of plugin-owned tables/transients; mutation cannot use a cached result.
$wpdb->query(
$wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_timeout_webdecoy_') . '%')
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// For multisite, clean up each site
if (is_multisite()) {
$sites = get_sites(['fields' => 'ids']);
foreach ($sites as $site_id) {
switch_to_blog($site_id);
// Drop tables for this site
$tables = [
$wpdb->prefix . 'webdecoy_blocked_ips',
$wpdb->prefix . 'webdecoy_detections',
$wpdb->prefix . 'webdecoy_rate_limits',
$wpdb->prefix . 'webdecoy_checkout_attempts',
$wpdb->prefix . 'webdecoy_ai_referrals',
$wpdb->prefix . 'webdecoy_request_counts',
$wpdb->prefix . 'webdecoy_crawler_visits',
$wpdb->prefix . 'webdecoy_ai_referral_days',
];
foreach ($tables as $table) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name is safe, built from $wpdb->prefix
$wpdb->query("DROP TABLE IF EXISTS {$table}");
}
// Delete options for this site
delete_option('webdecoy_options');
delete_option('webdecoy_db_version');
delete_option('webdecoy_request_counts_started_at');
delete_option('webdecoy_api_status');
delete_option('webdecoy_api_last_check');
delete_option('webdecoy_api_last_error');
delete_option('webdecoy_encryption_key');
delete_option('webdecoy_entitlements');
delete_option('webdecoy_actor_feed_cursor');
delete_option('webdecoy_critical_moment_last');
// Clear scheduled events for this site
wp_clear_scheduled_hook('webdecoy_cleanup_expired');
wp_clear_scheduled_hook('webdecoy_sync_blocked_ips');
wp_clear_scheduled_hook('webdecoy_sync_entitlements');
wp_clear_scheduled_hook('webdecoy_sync_actor_feed');
wp_clear_scheduled_hook('webdecoy_flush_ai_referrals');
// Delete transients for this site
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Explicit uninstall cleanup of plugin-owned tables/transients; mutation cannot use a cached result.
$wpdb->query(
$wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_webdecoy_') . '%')
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Explicit uninstall cleanup of plugin-owned tables/transients; mutation cannot use a cached result.
$wpdb->query(
$wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('_transient_timeout_webdecoy_') . '%')
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
restore_current_blog();
}
}