PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.3
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.3
3.0.0 2.11.12 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 All 88 releases
vigilante / uninstall.php

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

291 lines 10.8 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 }
72
73 // Remove backup directory. WP_CONTENT_DIR is shared by the whole network,
74 // so this happens once.
75 $backup_dir = WP_CONTENT_DIR . '/vigilante-backups/';
76 if ( is_dir( $backup_dir ) ) {
77 vigilante_recursive_rmdir( $backup_dir );
78 }
79
80 // Delete all user meta with vigilante_ prefix. The usermeta table is global
81 // on a network, so this also happens once.
82 // 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.
83 $wpdb->query(
84 "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'vigilante\_%'"
85 );
86
87 /*
88 * The plugin is still loaded in the request that runs this file, so
89 * whatever it does later, on shutdown or on a late hook, writes its data
90 * back after the cleanup above has finished. Measured on 22 aug 2026: an
91 * uninstall left 112 rows of plugin status transients and its last check
92 * timestamp behind, all of them written after this file had run. So the
93 * sweep is repeated at the very end of the request. The loaded plugin is
94 * the current site's instance and writes to the current site, which is
95 * why the sweep does not visit the network again.
96 */
97 add_action( 'shutdown', 'vigilante_uninstall_final_sweep', PHP_INT_MAX );
98 }
99
100 /**
101 * Remove the data of the current site (tables, options, transients, cron)
102 *
103 * Runs once on a single site and once per site on a network, after
104 * switch_to_blog().
105 *
106 * @since 2.11.0 Extracted from vigilante_uninstall() so a network can loop it.
107 */
108 function vigilante_uninstall_site() {
109 global $wpdb;
110
111 /*
112 * The scheduled events go first. WordPress can spawn wp-cron in the middle
113 * of an uninstall, and that loopback request runs in its own process with
114 * the plugin still on disk: clearing the events before anything else means
115 * it finds nothing to run.
116 */
117 // Clear scheduled hooks
118 $hooks_to_clear = array(
119 'vigilante_daily_maintenance',
120 'vigilante_hourly_check',
121 'vigilante_hourly_checks',
122 'vigilante_file_integrity_scan',
123 'vigilante_cleanup_logs',
124 'vigilante_password_expiry_reminder',
125 'vigilante_analyzer_weekly_scan',
126 'vigilante_under_attack_post_scan',
127 'vigilante_plugin_status_check',
128 );
129
130 foreach ( $hooks_to_clear as $hook ) {
131 wp_clear_scheduled_hook( $hook );
132 }
133
134 // Post-update verification events are scheduled with per-update arguments,
135 // so clear every instance regardless of args.
136 wp_unschedule_hook( 'vigilante_fi_postupdate_verify' );
137
138 // Drop custom tables
139 $tables = array(
140 $wpdb->prefix . 'vigilante_activity_log',
141 $wpdb->prefix . 'vigilante_login_attempts',
142 $wpdb->prefix . 'vigilante_file_integrity',
143 $wpdb->prefix . 'vigilante_2fa_codes',
144 $wpdb->prefix . 'vigilante_2fa_trusted_devices',
145 $wpdb->prefix . 'vigilante_2fa_notifications',
146 $wpdb->prefix . 'vigilante_2fa_totp',
147 );
148
149 foreach ( $tables as $table ) {
150 // 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.
151 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
152 }
153
154 // Delete options
155 $options_to_delete = array(
156 'vigilante_options',
157 'vigilante_db_version',
158 'vigilante_backup_timestamp',
159 'vigilante_last_integrity_scan',
160 'vigilante_last_integrity_results',
161 'vigilante_ignored_files',
162 'vigilante_dismissed_notices',
163 'vigilante_under_attack_mode',
164 'vigilante_active_preset',
165 'vigilante_firewall_blocks',
166 'vigilante_critical_files_baseline',
167 'vigilante_activated_time',
168 'vigilante_analyzer_last_scan',
169 'vigilante_analyzer_history',
170 'vigilante_legacy_backups_cleaned',
171 'vigilante_css_exclusion_migrated',
172 'vigilante_checksum_cache_flushed_290',
173 'vigilante_server_software',
174 'vigilante_server_files_version',
175 'vigilante_server_files_pending',
176 'vigilante_server_files_retry_after',
177 // Safety copies taken before writing to the site's configuration files.
178 // The wp-config.php one holds the database credentials and the
179 // authentication salts, so leaving it behind would keep them readable in
180 // the options table long after the plugin is gone.
181 'vigilante_htaccess_backup',
182 'vigilante_wpconfig_backup',
183 'vigilante_plugin_status_state',
184 'vigilante_plugin_status_last_check',
185 'vigilante_ignored_closed_plugins',
186 );
187
188 foreach ( $options_to_delete as $option ) {
189 delete_option( $option );
190 }
191
192 // Per-backup records are named after their timestamp
193 // (vigilante_backup_info_<Y-m-d_H-i-s>), so a fixed list cannot reach them.
194 // 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.
195 $wpdb->query(
196 "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'vigilante_backup_info_%'"
197 );
198
199 // Delete all transients
200 // 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.
201 $wpdb->query(
202 "DELETE FROM {$wpdb->options}
203 WHERE option_name LIKE '_transient_vigilante_%'
204 OR option_name LIKE '_transient_timeout_vigilante_%'"
205 );
206 }
207
208 /**
209 * Second pass at the end of the request, for anything written after the first one
210 *
211 * Deliberately not a blunt "vigilante%" wildcard: other plugins live under that
212 * name too, the network sync companion among them, and deleting their options
213 * from here would be a fine way to break somebody else's site.
214 *
215 * @since 2.9.9
216 */
217 function vigilante_uninstall_final_sweep() {
218 global $wpdb;
219
220 // The scheduled events go too: they are rescheduled by the plugin that is
221 // still loaded in this request, which is how vigilante_plugin_status_check
222 // survived an uninstall until 2.9.9.
223 $hooks = array(
224 'vigilante_daily_maintenance',
225 'vigilante_hourly_check',
226 'vigilante_hourly_checks',
227 'vigilante_file_integrity_scan',
228 'vigilante_cleanup_logs',
229 'vigilante_password_expiry_reminder',
230 'vigilante_analyzer_weekly_scan',
231 'vigilante_under_attack_post_scan',
232 'vigilante_plugin_status_check',
233 'vigilante_fi_postupdate_verify',
234 );
235
236 foreach ( $hooks as $hook ) {
237 wp_unschedule_hook( $hook );
238 }
239
240 // 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.
241 $wpdb->query(
242 "DELETE FROM {$wpdb->options}
243 WHERE option_name LIKE '_transient_vigilante\_%'
244 OR option_name LIKE '_transient_timeout_vigilante\_%'
245 OR option_name LIKE 'vigilante_plugin_status\_%'
246 OR option_name LIKE 'vigilante_backup_info\_%'
247 OR option_name IN (
248 'vigilante_options',
249 'vigilante_db_version',
250 'vigilante_ignored_closed_plugins',
251 'vigilante_ignored_files',
252 'vigilante_dismissed_notices',
253 'vigilante_under_attack_mode',
254 'vigilante_active_preset',
255 'vigilante_server_software',
256 'vigilante_server_files_version',
257 'vigilante_server_files_pending',
258 'vigilante_server_files_retry_after'
259 )"
260 );
261 }
262
263 /**
264 * Recursively remove directory
265 *
266 * @param string $dir Directory path.
267 * @return bool
268 */
269 function vigilante_recursive_rmdir( $dir ) {
270 if ( ! is_dir( $dir ) ) {
271 return false;
272 }
273
274 // Initialize WP_Filesystem
275 global $wp_filesystem;
276 if ( ! function_exists( 'WP_Filesystem' ) ) {
277 require_once ABSPATH . 'wp-admin/includes/file.php';
278 }
279 WP_Filesystem();
280
281 if ( ! $wp_filesystem ) {
282 return false;
283 }
284
285 // Use WP_Filesystem delete with recursive flag
286 return $wp_filesystem->delete( $dir, true );
287 }
288
289 // Run uninstall
290 vigilante_uninstall();
291