-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
126 lines (112 loc) · 4.07 KB
/
uninstall.php
File metadata and controls
126 lines (112 loc) · 4.07 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
<?php
/**
* Web200 Accessibility Audit uninstall routine.
*
* @package web200-accessibility-audit
*/
declare(strict_types=1);
if (! defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
/**
* Remove plugin data for the current site.
*/
function wcag_guard_uninstall_cleanup_current_site(): void
{
global $wpdb;
$option_keys = [
'wcag_guard_db_version',
'wcag_guard_schema_ready',
'wcag_guard_runtime_fixes',
'wcag_guard_keyboard_operable_selectors',
'wcag_guard_toolbar_presentation',
'wcag_guard_scheduler_enabled',
'wcag_guard_scheduler_interval',
'wcag_guard_scheduler_max_urls',
'wcag_guard_scheduler_include_wc',
'wcag_guard_scheduler_last_run',
'wcag_guard_scheduler_last_summary',
'wcag_guard_queue_enabled',
'wcag_guard_queue_interval',
'wcag_guard_queue_batch_size',
'wcag_guard_queue_max_attempts',
'wcag_guard_queue_last_run',
'wcag_guard_queue_last_report',
'wcag_guard_scan_engine_mode',
'wcag_guard_ci_gate_thresholds',
'wcag_guard_prepublish_gate',
'wcag_guard_checklist_state',
'wcag_guard_pro_license_state',
'wcag_guard_uninstall_delete_data',
];
foreach ($option_keys as $option_key) {
delete_option($option_key);
}
if (function_exists('wp_clear_scheduled_hook')) {
wp_clear_scheduled_hook('wcag_guard_scheduled_scan');
wp_clear_scheduled_hook('wcag_guard_scan_queue_worker');
} else {
$next = wp_next_scheduled('wcag_guard_scheduled_scan');
while ($next !== false) {
wp_unschedule_event((int) $next, 'wcag_guard_scheduled_scan');
$next = wp_next_scheduled('wcag_guard_scheduled_scan');
}
$next_queue = wp_next_scheduled('wcag_guard_scan_queue_worker');
while ($next_queue !== false) {
wp_unschedule_event((int) $next_queue, 'wcag_guard_scan_queue_worker');
$next_queue = wp_next_scheduled('wcag_guard_scan_queue_worker');
}
}
$tables = [
$wpdb->prefix . 'wcag_guard_scans',
$wpdb->prefix . 'wcag_guard_issues',
$wpdb->prefix . 'wcag_guard_fix_actions',
$wpdb->prefix . 'wcag_guard_scan_queue',
];
foreach ($tables as $table_name) {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall cleanup intentionally drops plugin tables.
$wpdb->query(
$wpdb->prepare(
'DROP TABLE IF EXISTS %i',
$table_name
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange
}
}
/**
* Resolve whether plugin data should be deleted for a site.
*/
function wcag_guard_uninstall_should_delete_data_for_site(int $site_id = 0): bool
{
$delete_data = (bool) get_option('wcag_guard_uninstall_delete_data', false);
/**
* Filters whether Web200 Accessibility Audit should delete data on uninstall.
*
* @param bool $delete_data Current site preference.
* @param int $site_id Site ID in multisite context (0 for single site).
*/
return (bool) apply_filters('wcag_guard_uninstall_remove_data', $delete_data, $site_id);
}
if (is_multisite()) {
$wcag_guard_site_ids = get_sites(
[
'fields' => 'ids',
'number' => 0,
]
);
if (is_array($wcag_guard_site_ids)) {
foreach ($wcag_guard_site_ids as $wcag_guard_site_id) {
switch_to_blog((int) $wcag_guard_site_id);
if (wcag_guard_uninstall_should_delete_data_for_site((int) $wcag_guard_site_id)) {
wcag_guard_uninstall_cleanup_current_site();
}
restore_current_blog();
}
}
delete_site_option('wcag_guard_uninstall_delete_data');
} else {
if (wcag_guard_uninstall_should_delete_data_for_site()) {
wcag_guard_uninstall_cleanup_current_site();
}
}