PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.9
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.9
2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 2.9.4 2.9.3 All 86 releases
vigilante / uninstall.php

uninstall.php in Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… 2.11.9, at uninstall.php

314 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall Vigilante AyudaWP
4 *
5 * This file runs when the plugin is deleted via WordPress admin.
6 * It removes all plugin data including database tables and options.
7 *
8 * On a network it visits every site: tables, options, transients and cron
9 * events are per site, so cleaning only the site that runs the uninstall
10 * left everything else behind until 2.11.0 (S13 of the 28 Aug 2026 audit).
11 *
12 * @package Vigilante
13 */
14
15 // Exit if not called by WordPress
16 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
17 exit;
18 }
19
20 // Load required files
21 require_once plugin_dir_path( __FILE__ ) . 'includes/class-settings.php';
22 require_once plugin_dir_path( __FILE__ ) . 'includes/class-database.php';
23 require_once plugin_dir_path( __FILE__ ) . 'includes/class-backup-manager.php';
24 require_once plugin_dir_path( __FILE__ ) . 'includes/class-deactivator.php';
25
26 // Define constants if not already defined
27 if ( ! defined( 'VIGILANTE_BACKUP_DIR' ) ) {
28 define( 'VIGILANTE_BACKUP_DIR', WP_CONTENT_DIR . '/vigilante-backups/' );
29 }
30
31 /**
32 * Uninstall function
33 */
34 function vigilante_uninstall() {
35 global $wpdb;
36
37 /*
38 * Per-site data. switch_to_blog() repoints $wpdb->prefix, $wpdb->options
39 * and the cron option, so the same routine serves every site of a network.
40 * 'number' => 0 lifts the default cap of 100 sites: an uninstall that
41 * cleaned the first hundred sites and left the rest would be the same bug
42 * with a bigger threshold.
43 */
44 if ( is_multisite() ) {
45 $site_ids = get_sites(
46 array(
47 'fields' => 'ids',
48 'number' => 0,
49 )
50 );
51
52 foreach ( $site_ids as $site_id ) {
53 switch_to_blog( $site_id );
54 vigilante_uninstall_site();
55 restore_current_blog();
56 }
57 } else {
58 vigilante_uninstall_site();
59 }
60
61 /*
62 * Network options. Since 2.11.3 the baseline of the critical files lives in
63 * a single network option, because both files it watches, wp-config.php and
64 * the root .htaccess, belong to the installation and not to any one site.
65 * It is stored redacted, but it is still a copy of the configuration and it
66 * goes when the plugin goes. Once, not per site.
67 */
68 if ( is_multisite() ) {
69 delete_site_option( 'vigilante_critical_files_baseline' );
70 delete_site_option( 'vigilante_baseline_sweep' );
71 delete_site_option( 'vigilante_owned_blocks' );
72 delete_site_option( 'vigilante_owned_blocks_claim' );
73 delete_site_option( 'vigilante_config_copies_sweep' );
74 delete_site_option( 'vigilante_results_sweep' );
75 }
76
77 // Remove backup directory. WP_CONTENT_DIR is shared by the whole network,
78 // so this happens once.
79 $backup_dir = WP_CONTENT_DIR . '/vigilante-backups/';
80 if ( is_dir( $backup_dir ) ) {
81 vigilante_recursive_rmdir( $backup_dir );
82 }
83
84 // Delete all user meta with vigilante_ prefix. The usermeta table is global
85 // on a network, so this also happens once.
86 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own user meta (prefix vigilante_) swept by pattern at uninstall; no cache to invalidate once the plugin is gone.
87 $wpdb->query(
88 "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'vigilante\_%'"
89 );
90
91 /*
92 * The plugin is still loaded in the request that runs this file, so
93 * whatever it does later, on shutdown or on a late hook, writes its data
94 * back after the cleanup above has finished. Measured on 22 aug 2026: an
95 * uninstall left 112 rows of plugin status transients and its last check
96 * timestamp behind, all of them written after this file had run. So the
97 * sweep is repeated at the very end of the request. The loaded plugin is
98 * the current site's instance and writes to the current site, which is
99 * why the sweep does not visit the network again.
100 */
101 add_action( 'shutdown', 'vigilante_uninstall_final_sweep', PHP_INT_MAX );
102 }
103
104 /**
105 * Remove the data of the current site (tables, options, transients, cron)
106 *
107 * Runs once on a single site and once per site on a network, after
108 * switch_to_blog().
109 *
110 * @since 2.11.0 Extracted from vigilante_uninstall() so a network can loop it.
111 */
112 function vigilante_uninstall_site() {
113 global $wpdb;
114
115 /*
116 * The scheduled events go first. WordPress can spawn wp-cron in the middle
117 * of an uninstall, and that loopback request runs in its own process with
118 * the plugin still on disk: clearing the events before anything else means
119 * it finds nothing to run.
120 */
121 // Clear scheduled hooks
122 $hooks_to_clear = array(
123 'vigilante_daily_maintenance',
124 'vigilante_hourly_check',
125 'vigilante_hourly_checks',
126 'vigilante_file_integrity_scan',
127 'vigilante_cleanup_logs',
128 'vigilante_password_expiry_reminder',
129 'vigilante_analyzer_weekly_scan',
130 'vigilante_under_attack_post_scan',
131 'vigilante_plugin_status_check',
132 );
133
134 foreach ( $hooks_to_clear as $hook ) {
135 wp_clear_scheduled_hook( $hook );
136 }
137
138 // Post-update verification events are scheduled with per-update arguments,
139 // so clear every instance regardless of args.
140 wp_unschedule_hook( 'vigilante_fi_postupdate_verify' );
141
142 // Drop custom tables
143 $tables = array(
144 $wpdb->prefix . 'vigilante_activity_log',
145 $wpdb->prefix . 'vigilante_login_attempts',
146 $wpdb->prefix . 'vigilante_file_integrity',
147 $wpdb->prefix . 'vigilante_2fa_codes',
148 $wpdb->prefix . 'vigilante_2fa_trusted_devices',
149 $wpdb->prefix . 'vigilante_2fa_notifications',
150 $wpdb->prefix . 'vigilante_2fa_totp',
151 );
152
153 foreach ( $tables as $table ) {
154 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Dropping the plugin's own tables at uninstall; the name comes from $wpdb->prefix and a literal, never from input.
155 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
156 }
157
158 // Delete options
159 $options_to_delete = array(
160 'vigilante_options',
161 'vigilante_db_version',
162 'vigilante_purge_2_11_0_done',
163 'vigilante_baseline_redaction',
164 'vigilante_owned_blocks',
165 'vigilante_owned_blocks_claim',
166 'vigilante_backup_timestamp',
167 'vigilante_last_integrity_scan',
168 'vigilante_last_integrity_results',
169 'vigilante_ignored_files',
170 'vigilante_dismissed_notices',
171 'vigilante_under_attack_mode',
172 'vigilante_active_preset',
173 'vigilante_firewall_blocks',
174 'vigilante_critical_files_baseline',
175 'vigilante_activated_time',
176 'vigilante_analyzer_last_scan',
177 'vigilante_analyzer_history',
178 'vigilante_legacy_backups_cleaned',
179 'vigilante_css_exclusion_migrated',
180 'vigilante_checksum_cache_flushed_290',
181 'vigilante_server_software',
182 'vigilante_server_files_version',
183 'vigilante_server_files_pending',
184 'vigilante_server_files_retry_after',
185 // Safety copies taken before writing to the site's configuration files.
186 // The wp-config.php one holds the database credentials and the
187 // authentication salts, so leaving it behind would keep them readable in
188 // the options table long after the plugin is gone.
189 'vigilante_htaccess_backup',
190 'vigilante_htaccess_history',
191 // The pre-migration snapshot keeps our own header block so the owner can
192 // restore it; it is still ours to remove on uninstall, along with the
193 // recovery undo copy and the dismissed flag.
194 'vigilante_htaccess_pre_migration',
195 'vigilante_htaccess_recovery_undo',
196 'vigilante_htaccess_recovery_done',
197 'vigilante_wpconfig_backup',
198 'vigilante_config_copies_purged',
199 'vigilante_config_copies_sweep_lock',
200 'vigilante_htaccess_write_lock',
201 'vigilante_plugin_status_state',
202 'vigilante_plugin_status_last_check',
203 'vigilante_ignored_closed_plugins',
204 );
205
206 foreach ( $options_to_delete as $option ) {
207 delete_option( $option );
208 }
209
210 // Per-backup records are named after their timestamp
211 // (vigilante_backup_info_<Y-m-d_H-i-s>), so a fixed list cannot reach them.
212 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own options swept by pattern at uninstall; the options API has no LIKE.
213 $wpdb->query(
214 "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'vigilante_backup_info_%'"
215 );
216
217 // Delete all transients
218 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own transients swept by pattern at uninstall; the transients API has no LIKE.
219 $wpdb->query(
220 "DELETE FROM {$wpdb->options}
221 WHERE option_name LIKE '_transient_vigilante_%'
222 OR option_name LIKE '_transient_timeout_vigilante_%'"
223 );
224 }
225
226 /**
227 * Second pass at the end of the request, for anything written after the first one
228 *
229 * Deliberately not a blunt "vigilante%" wildcard: other plugins live under that
230 * name too, the network sync companion among them, and deleting their options
231 * from here would be a fine way to break somebody else's site.
232 *
233 * @since 2.9.9
234 */
235 function vigilante_uninstall_final_sweep() {
236 global $wpdb;
237
238 // The scheduled events go too: they are rescheduled by the plugin that is
239 // still loaded in this request, which is how vigilante_plugin_status_check
240 // survived an uninstall until 2.9.9.
241 $hooks = array(
242 'vigilante_daily_maintenance',
243 'vigilante_hourly_check',
244 'vigilante_hourly_checks',
245 'vigilante_file_integrity_scan',
246 'vigilante_cleanup_logs',
247 'vigilante_password_expiry_reminder',
248 'vigilante_analyzer_weekly_scan',
249 'vigilante_under_attack_post_scan',
250 'vigilante_plugin_status_check',
251 'vigilante_fi_postupdate_verify',
252 );
253
254 foreach ( $hooks as $hook ) {
255 wp_unschedule_hook( $hook );
256 }
257
258 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Same sweep as vigilante_uninstall_site(), repeated at shutdown for rows the still-loaded plugin wrote back after the first pass.
259 $wpdb->query(
260 "DELETE FROM {$wpdb->options}
261 WHERE option_name LIKE '_transient_vigilante\_%'
262 OR option_name LIKE '_transient_timeout_vigilante\_%'
263 OR option_name LIKE 'vigilante_plugin_status\_%'
264 OR option_name LIKE 'vigilante_backup_info\_%'
265 OR option_name IN (
266 'vigilante_options',
267 'vigilante_db_version',
268 'vigilante_purge_2_11_0_done',
269 'vigilante_baseline_redaction',
270 'vigilante_critical_files_baseline',
271 'vigilante_owned_blocks',
272 'vigilante_owned_blocks_claim',
273 'vigilante_ignored_closed_plugins',
274 'vigilante_ignored_files',
275 'vigilante_dismissed_notices',
276 'vigilante_under_attack_mode',
277 'vigilante_active_preset',
278 'vigilante_server_software',
279 'vigilante_server_files_version',
280 'vigilante_server_files_pending',
281 'vigilante_server_files_retry_after'
282 )"
283 );
284 }
285
286 /**
287 * Recursively remove directory
288 *
289 * @param string $dir Directory path.
290 * @return bool
291 */
292 function vigilante_recursive_rmdir( $dir ) {
293 if ( ! is_dir( $dir ) ) {
294 return false;
295 }
296
297 // Initialize WP_Filesystem
298 global $wp_filesystem;
299 if ( ! function_exists( 'WP_Filesystem' ) ) {
300 require_once ABSPATH . 'wp-admin/includes/file.php';
301 }
302 WP_Filesystem();
303
304 if ( ! $wp_filesystem ) {
305 return false;
306 }
307
308 // Use WP_Filesystem delete with recursive flag
309 return $wp_filesystem->delete( $dir, true );
310 }
311
312 // Run uninstall
313 vigilante_uninstall();
314