-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuninstall.php
96 lines (74 loc) · 3.54 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
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
<?php
if (get_option('presspermit_delete_settings_on_uninstall')) {
global $wpdb;
// Since stored settings are shared among all installed versions,
// all copies of the plugin (both Pro and Free) need to be deleted (not just deactivated) before deleting any settings.
$permissions_plugin_count = 0;
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$_plugins = get_plugins();
foreach($_plugins as $_plugin) {
if (!empty($_plugin['Title']) && in_array($_plugin['Title'], ['PublishPress Permissions', 'PublishPress Permissions Pro'])) {
$permissions_plugin_count++;
}
}
if ($permissions_plugin_count === 1) {
$orig_site_id = get_current_blog_id();
$site_ids = (function_exists('get_sites')) ? get_sites(['fields' => 'ids']) : (array) $orig_site_id;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
foreach ($site_ids as $_blog_id) {
if (is_multisite()) {
switch_to_blog($_blog_id);
}
if (!empty($wpdb->options)) {
@$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%presspermit%'");
@$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'ppperm_%'");
}
delete_option('ppcc_version');
delete_option('ppce_version');
delete_option('ppi_version');
delete_option('ppm_version');
delete_option('ppp_version');
delete_option('pps_version');
wp_load_alloptions(true);
if (!empty($wpdb->postmeta)) {
@$wpdb->query(
"DELETE FROM $wpdb->postmeta WHERE meta_key IN ("
. "'_pp_wpml_mirrored_exceptions', '_rs_file_key', '_last_attachment_ids', '_last_category_ids', '_last_post_tag_ids', '_pp_last_parent', '_scheduled_status', '_pp_original_status', '_pp_sync_author_id', '_pp_is_autodraft', '_pp_is_auto_inserted'"
. ")"
);
}
// phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
if (!empty($wpdb->pp_groups)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->pp_groups");
}
if (!empty($wpdb->pp_group_members)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->pp_group_members");
}
if (!empty($wpdb->ppc_roles)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppc_roles");
}
if (!empty($wpdb->ppc_exceptions)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppc_exceptions");
}
if (!empty($wpdb->ppc_exception_items)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppc_exception_items");
}
if (!empty($wpdb->pp_circles)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->pp_circles");
}
if (!empty($wpdb->pp_conditions)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->pp_conditions");
}
if (!empty($wpdb->ppi_runs)) {
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppi_runs");
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppi_imported");
@$wpdb->query("DROP TABLE IF EXISTS $wpdb->ppi_errors");
}
}
if (is_multisite()) {
switch_to_blog($orig_site_id);
}
}
}