-
Notifications
You must be signed in to change notification settings - Fork 36
/
uninstall.php
64 lines (55 loc) · 1.8 KB
/
uninstall.php
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
<?php
//if uninstall not called from WordPress exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit();
}
/** @var wpdb $wpdb */
global $wpdb;
// only uninstall if no BackWPup Version active.
if ( ! class_exists( \BackWPup::class ) ) {
//delete plugin options
if (is_multisite()) {
$wpdb->query('DELETE FROM ' . $wpdb->sitemeta . " WHERE meta_key LIKE '%backwpup_%' ");
} else {
$wpdb->query('DELETE FROM ' . $wpdb->options . " WHERE option_name LIKE '%backwpup_%' ");
}
//delete Backwpup user roles
// Special handling for multisite when network-activated.
if (is_multisite()) {
$sites = get_sites([
'fields' => 'ids',
]);
$current_site = get_current_blog_id();
foreach ($sites as $site) {
switch_to_blog($site);
backwpup_remove_roles();
}
switch_to_blog($current_site);
} else {
backwpup_remove_roles();
}
}
/**
* Removes BackWPup roles and capabilities.
*/
function backwpup_remove_roles()
{
remove_role('backwpup_admin');
remove_role('backwpup_helper');
remove_role('backwpup_check');
//remove capabilities to administrator role
$role = get_role('administrator');
if (is_object($role) && method_exists($role, 'remove_cap')) {
$role->remove_cap('backwpup');
$role->remove_cap('backwpup_jobs');
$role->remove_cap('backwpup_jobs_edit');
$role->remove_cap('backwpup_jobs_start');
$role->remove_cap('backwpup_backups');
$role->remove_cap('backwpup_backups_download');
$role->remove_cap('backwpup_backups_delete');
$role->remove_cap('backwpup_logs');
$role->remove_cap('backwpup_logs_delete');
$role->remove_cap('backwpup_settings');
$role->remove_cap('backwpup_restore');
}
}