forked from 10up/ElasticPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
211 lines (187 loc) · 6.94 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* ElasticPress uninstaller
*
* Used when clicking "Delete" from inside of WordPress's plugins page.
*
* @package elasticpress
* @since 1.7
*/
/**
* Class EP_Uninstaller
*/
class EP_Uninstaller {
/**
* Initialize uninstaller
*
* Perform some checks to make sure plugin can/should be uninstalled
*
* @since 1.7
* @return EP_Uninstaller
*/
public function __construct() {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
$this->exit_uninstaller();
}
// Not uninstalling.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
$this->exit_uninstaller();
}
// Not uninstalling.
if ( ! WP_UNINSTALL_PLUGIN ) {
$this->exit_uninstaller();
}
// Not uninstalling this plugin.
if ( dirname( WP_UNINSTALL_PLUGIN ) !== dirname( plugin_basename( __FILE__ ) ) ) {
$this->exit_uninstaller();
}
// Uninstall ElasticPress.
self::clean_options();
}
/**
* Cleanup options
*
* Deletes ElasticPress options and transients.
*
* @since 1.7
* @return void
*/
protected static function clean_options() {
global $wpdb;
// Delete ep_related_posts_* transients
if ( is_multisite() ) {
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
// Delete options.
delete_option( 'ep_host' );
delete_site_option( 'ep_index_meta' );
delete_option( 'ep_index_meta' );
delete_site_option( 'ep_feature_settings' );
delete_option( 'ep_feature_settings' );
delete_site_option( 'ep_version' );
delete_option( 'ep_version' );
delete_option( 'ep_intro_shown' );
delete_site_option( 'ep_intro_shown' );
delete_option( 'ep_last_sync' );
delete_site_option( 'ep_last_sync' );
delete_option( 'ep_need_upgrade_sync' );
delete_site_option( 'ep_need_upgrade_sync' );
delete_option( 'ep_feature_requirement_statuses' );
delete_site_option( 'ep_feature_requirement_statuses' );
delete_option( 'ep_feature_auto_activated_sync' );
delete_site_option( 'ep_feature_auto_activated_sync' );
delete_option( 'ep_hide_intro_shown_notice' );
delete_site_option( 'ep_hide_intro_shown_notice' );
delete_option( 'ep_skip_install' );
delete_site_option( 'ep_skip_install' );
delete_option( 'ep_last_cli_index' );
delete_site_option( 'ep_last_cli_index' );
delete_option( 'ep_credentials' );
delete_site_option( 'ep_credentials' );
delete_option( 'ep_prefix' );
delete_site_option( 'ep_prefix' );
delete_option( 'ep_language' );
delete_site_option( 'ep_language' );
delete_option( 'ep_bulk_setting' );
delete_site_option( 'ep_bulk_setting' );
// Delete admin notices options
delete_site_option( 'ep_hide_host_error_notice' );
delete_option( 'ep_hide_host_error_notice' );
delete_site_option( 'ep_hide_es_below_compat_notice' );
delete_option( 'ep_hide_es_below_compat_notice' );
delete_site_option( 'ep_hide_es_above_compat_notice' );
delete_option( 'ep_hide_es_above_compat_notice' );
delete_site_option( 'ep_hide_need_setup_notice' );
delete_option( 'ep_hide_need_setup_notice' );
delete_site_option( 'ep_hide_no_sync_notice' );
delete_option( 'ep_hide_no_sync_notice' );
delete_site_option( 'ep_hide_upgrade_sync_notice' );
delete_option( 'ep_hide_upgrade_sync_notice' );
delete_site_option( 'ep_hide_auto_activate_sync_notice' );
delete_option( 'ep_hide_auto_activate_sync_notice' );
delete_site_option( 'ep_hide_using_autosuggest_defaults_notice' );
delete_option( 'ep_hide_using_autosuggest_defaults_notice' );
delete_site_option( 'ep_hide_yellow_health_notice' );
delete_option( 'ep_hide_yellow_health_notice' );
// Delete transients
delete_site_transient( 'ep_es_info_response_code' );
delete_transient( 'ep_es_info_response_code' );
delete_site_transient( 'ep_es_info_response_error' );
delete_transient( 'ep_es_info_response_error' );
delete_site_transient( 'logging_ep_es_info' );
delete_transient( 'logging_ep_es_info' );
delete_site_transient( 'ep_wpcli_sync_interrupted' );
delete_transient( 'ep_wpcli_sync_interrupted' );
delete_site_transient( 'ep_wpcli_sync' );
delete_transient( 'ep_wpcli_sync' );
delete_site_transient( 'ep_es_info' );
delete_transient( 'ep_es_info' );
delete_site_transient( 'ep_autosuggest_query_request_cache' );
delete_transient( 'ep_autosuggest_query_request_cache' );
$related_posts_transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE '_transient_ep_related_posts_%'" );
foreach ( $related_posts_transients as $related_posts_transient ) {
$related_posts_transient = str_replace( '_transient_', '', $related_posts_transient );
delete_site_transient( $related_posts_transient );
delete_transient( $related_posts_transient );
}
restore_current_blog();
}
} else {
// Delete options.
delete_option( 'ep_host' );
delete_option( 'ep_index_meta' );
delete_option( 'ep_feature_settings' );
delete_option( 'ep_version' );
delete_option( 'ep_intro_shown' );
delete_option( 'ep_last_sync' );
delete_option( 'ep_need_upgrade_sync' );
delete_option( 'ep_feature_requirement_statuses' );
delete_option( 'ep_feature_auto_activated_sync' );
delete_option( 'ep_hide_intro_shown_notice' );
delete_option( 'ep_skip_install' );
delete_option( 'ep_last_cli_index' );
delete_option( 'ep_credentials' );
delete_option( 'ep_prefix' );
delete_option( 'ep_language' );
delete_option( 'ep_bulk_setting' );
// Delete admin notices options
delete_option( 'ep_hide_host_error_notice' );
delete_option( 'ep_hide_es_below_compat_notice' );
delete_option( 'ep_hide_es_above_compat_notice' );
delete_option( 'ep_hide_need_setup_notice' );
delete_option( 'ep_hide_no_sync_notice' );
delete_option( 'ep_hide_upgrade_sync_notice' );
delete_option( 'ep_hide_auto_activate_sync_notice' );
delete_option( 'ep_hide_using_autosuggest_defaults_notice' );
delete_option( 'ep_hide_yellow_health_notice' );
// Delete transients
delete_transient( 'ep_es_info_response_code' );
delete_transient( 'ep_es_info_response_error' );
delete_transient( 'logging_ep_es_info' );
delete_transient( 'ep_wpcli_sync_interrupted' );
delete_transient( 'ep_wpcli_sync' );
delete_transient( 'ep_es_info' );
delete_transient( 'ep_autosuggest_query_request_cache' );
$related_posts_transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE '_transient_ep_related_posts_%'" );
foreach ( $related_posts_transients as $related_posts_transient ) {
$related_posts_transient = str_replace( '_transient_', '', $related_posts_transient );
delete_transient( $related_posts_transient );
}
}
}
/**
* Exit uninstaller
*
* Gracefully exit the uninstaller if we should not be here
*
* @since 1.7
* @return void
*/
protected function exit_uninstaller() {
status_header( 404 );
exit;
}
}
new EP_Uninstaller();