-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.php
More file actions
128 lines (107 loc) · 2.7 KB
/
uninstall.php
File metadata and controls
128 lines (107 loc) · 2.7 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
127
128
<?php
/**
* This will be executed when the plugin is uninstalled.
*
* @package OneUpdate
*/
declare( strict_types=1 );
namespace OneUpdate;
// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Multisite loop for uninstalling from all sites.
*/
function multisite_uninstall(): void {
if ( ! is_multisite() ) {
uninstall();
return;
}
delete_network_plugin_data();
$site_ids = get_sites(
[
'fields' => 'ids',
'number' => 0,
]
) ?: [];
foreach ( $site_ids as $site_id ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog
if ( ! switch_to_blog( (int) $site_id ) ) {
continue;
}
uninstall();
restore_current_blog();
}
}
/**
* The (site-specific) uninstall function.
*/
function uninstall(): void {
delete_plugin_data();
}
/**
* Delete multisite network plugin data.
*/
function delete_network_plugin_data(): void {
$options = [
'oneupdate_multisite_governing_site',
];
foreach ( $options as $option ) {
delete_site_option( $option );
}
}
/**
* Deletes meta, options, transients, etc.
*/
function delete_plugin_data(): void {
// list of actions to be cleared on uninstall.
$actions_to_clear = [
'oneupdate_s3_zip_cleanup_event',
'oneupdate_s3_zip_history_cleanup_event', // legacy cron to cleanup.
];
// Clear scheduled actions.
if ( function_exists( 'wp_clear_scheduled_hook' ) ) {
foreach ( $actions_to_clear as $action ) {
wp_clear_scheduled_hook( $action );
}
}
// Options to clean up.
$options = [
'oneupdate_child_site_api_key',
'oneupdate_child_site_public_key',
'oneupdate_consumer_api_key',
'oneupdate_db_version',
'oneupdate_gh_token',
'oneupdate_github_token',
'oneupdate_governing_site_url',
'oneupdate_new_users',
'oneupdate_parent_site_url',
'oneupdate_profile_update_requests',
'oneupdate_s3_credentials',
'oneupdate_shared_sites',
'oneupdate_site_type',
];
foreach ( $options as $option ) {
delete_option( $option );
}
// Transients to clean up.
$transients = [
'oneupdate_get_plugins',
'oneupdate_gh_repos',
];
foreach ( $transients as $transient ) {
delete_transient( $transient );
}
// Drop custom tables created by the OneUpdate.
$tables_to_drop = [
'wp_oneupdate_s3_zip_history',
];
global $wpdb;
foreach ( $tables_to_drop as $table ) {
$full_table_name = $wpdb->prefix . $table;
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $full_table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- this is to drop table on uninstall
}
}
// Run the uninstaller.
multisite_uninstall();