PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | uninstall.php +77 -30 4.4.15.3.5 View file →
@@ -7,8 +7,14 @@
7 7 * @package elasticpress
8 8 * @since 1.7
9 9 */
10 10
11 +use ElasticPress\Utils;
12 +
13 +defined( 'ABSPATH' ) || exit;
14 +
15 +require_once __DIR__ . '/includes/utils.php';
16 +
11 17 /**
12 18 * Class EP_Uninstaller
13 19 */
14 20 class EP_Uninstaller {
@@ -21,8 +27,9 @@
21 27 protected $options = [
22 28 'ep_host',
23 29 'ep_index_meta',
24 30 'ep_feature_settings',
31 + 'ep_feature_settings_draft',
25 32 'ep_version',
26 33 'ep_intro_shown',
27 34 'ep_last_sync',
28 35 'ep_need_upgrade_sync',
@@ -34,10 +41,12 @@
34 41 'ep_credentials',
35 42 'ep_prefix',
36 43 'ep_language',
37 44 'ep_bulk_setting',
38 - 'ep_last_index',
45 + 'ep_sync_history',
39 46
47 + 'elasticpress_weighting',
48 +
40 49 // Admin notices options
41 50 'ep_hide_host_error_notice',
42 51 'ep_hide_es_below_compat_notice',
43 52 'ep_hide_es_above_compat_notice',
@@ -54,16 +63,17 @@
54 63 *
55 64 * @var array
56 65 */
57 66 protected $transients = [
67 + 'ep_autosuggest_query_request_cache',
68 + 'ep_elasticpress_io_messages',
69 + 'ep_es_info',
58 70 'ep_es_info_response_code',
59 71 'ep_es_info_response_error',
72 + 'ep_meta_field_keys',
73 + 'ep_wpcli_sync',
74 + 'ep_wpcli_sync_interrupted',
60 75 'logging_ep_es_info',
61 - 'ep_wpcli_sync_interrupted',
62 - 'ep_wpcli_sync',
63 - 'ep_es_info',
64 - 'ep_autosuggest_query_request_cache',
65 - 'ep_meta_field_keys',
66 76 ];
67 77
68 78 /**
69 79 * Initialize uninstaller
@@ -70,17 +80,20 @@
70 80 *
71 81 * Perform some checks to make sure plugin can/should be uninstalled
72 82 *
73 83 * @since 1.7
74 - * @return EP_Uninstaller
75 84 */
76 85 public function __construct() {
77 -
78 86 // Exit if accessed directly.
79 87 if ( ! defined( 'ABSPATH' ) ) {
80 88 $this->exit_uninstaller();
81 89 }
82 90
91 + // If testing, do not do anything automatically
92 + if ( defined( 'EP_UNIT_TESTS' ) && EP_UNIT_TESTS ) {
93 + return;
94 + }
95 +
83 96 // EP_MANUAL_SETTINGS_RESET is used by the `settings-reset` WP-CLI command.
84 97 if ( ! defined( 'EP_MANUAL_SETTINGS_RESET' ) || ! EP_MANUAL_SETTINGS_RESET ) {
85 98 // Not uninstalling.
86 99 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) || ! WP_UNINSTALL_PLUGIN ) {
@@ -94,8 +107,10 @@
94 107 }
95 108
96 109 // Uninstall ElasticPress.
97 110 $this->clean_options_and_transients();
111 + $this->clean_site_meta();
112 + $this->remove_elasticpress_capability();
98 113 }
99 114
100 115 /**
101 116 * Delete all the options in a single site context.
@@ -115,35 +130,43 @@
115 130 }
116 131 }
117 132
118 133 /**
119 - * Delete all transients of the Related Posts feature.
134 + * Delete remaining transients by their option names.
135 + *
136 + * @since 4.7.0
120 137 */
121 - protected function delete_related_posts_transients() {
138 + protected function delete_transients_by_option_name() {
122 139 global $wpdb;
123 140
124 - $related_posts_transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE '_transient_ep_related_posts_%'" );
141 + $transients = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
142 + "SELECT option_name
143 + FROM {$wpdb->prefix}options
144 + WHERE
145 + option_name LIKE '_transient_ep_index_settings_%'
146 + OR option_name LIKE '_transient_ep_related_posts_%'
147 + "
148 + );
125 149
126 - foreach ( $related_posts_transients as $related_posts_transient ) {
127 - $related_posts_transient = str_replace( '_transient_', '', $related_posts_transient );
128 - delete_site_transient( $related_posts_transient );
129 - delete_transient( $related_posts_transient );
150 + foreach ( $transients as $transient ) {
151 + $transient_name = str_replace( '_transient_', '', $transient );
152 + delete_site_transient( $transient_name );
153 + delete_transient( $transient_name );
130 154 }
131 155 }
132 156
133 157 /**
134 - * Delete all transients of the total fields limit.
158 + * DEPRECATED. Delete all transients of the Related Posts feature.
135 159 */
160 + protected function delete_related_posts_transients() {
161 + _deprecated_function( __METHOD__, '4.7.0', '\EP_Uninstaller::delete_transients_by_name()' );
162 + }
163 +
164 + /**
165 + * DEPRECATED. Delete all transients of the total fields limit.
166 + */
136 167 protected function delete_total_fields_limit_transients() {
137 - global $wpdb;
138 -
139 - $related_posts_transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE '_transient_ep_total_fields_limit_%'" );
140 -
141 - foreach ( $related_posts_transients as $related_posts_transient ) {
142 - $related_posts_transient = str_replace( '_transient_', '', $related_posts_transient );
143 - delete_site_transient( $related_posts_transient );
144 - delete_transient( $related_posts_transient );
145 - }
168 + _deprecated_function( __METHOD__, '4.7.0', '\EP_Uninstaller::delete_transients_by_name()' );
146 169 }
147 170
148 171 /**
149 172 * Cleanup options and transients
@@ -160,9 +183,9 @@
160 183 foreach ( $this->transients as $transient ) {
161 184 delete_site_transient( $transient );
162 185 }
163 186
164 - $sites = get_sites();
187 + $sites = \get_sites();
165 188
166 189 foreach ( $sites as $site ) {
167 190 switch_to_blog( $site->blog_id );
168 191
@@ -167,10 +190,9 @@
167 190 switch_to_blog( $site->blog_id );
168 191
169 192 $this->delete_options();
170 193 $this->delete_transients();
171 - $this->delete_related_posts_transients();
172 - $this->delete_total_fields_limit_transients();
194 + $this->delete_transients_by_option_name();
173 195
174 196 restore_current_blog();
175 197 }
176 198 } else {
@@ -175,11 +197,36 @@
175 197 }
176 198 } else {
177 199 $this->delete_options();
178 200 $this->delete_transients();
179 - $this->delete_related_posts_transients();
180 - $this->delete_total_fields_limit_transients();
201 + $this->delete_transients_by_option_name();
181 202 }
203 + }
204 +
205 + /**
206 + * Delete all site meta
207 + *
208 + * @since 4.7.0
209 + */
210 + protected function clean_site_meta() {
211 + if ( ! is_multisite() ) {
212 + return;
213 + }
214 +
215 + $sites = Utils\get_sites();
216 + foreach ( $sites as $site ) {
217 + delete_site_meta( $site['blog_id'], 'ep_indexable' );
218 + }
219 + }
220 +
221 + /**
222 + * Remove the ElasticPress' capability
223 + *
224 + * @since 4.5.0
225 + */
226 + protected function remove_elasticpress_capability() {
227 + $role = get_role( 'administrator' );
228 + $role->remove_cap( Utils\get_capability() );
182 229 }
183 230
184 231 /**
185 232 * Cleanup options (deprecated, kept for documenting reasons.)