PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.2
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.2
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.2, at uninstall.php

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