PluginProbe
ElasticPress / 4.4.1
ElasticPress v4.4.1
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
elasticpress / uninstall.php

uninstall.php in ElasticPress 4.4.1, at uninstall.php

210 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ElasticPress uninstaller
4 *
5 * Used when clicking "Delete" from inside of WordPress's plugins page.
6 *
7 * @package elasticpress
8 * @since 1.7
9 */
10
11 /**
12 * Class EP_Uninstaller
13 */
14 class EP_Uninstaller {
15
16 /**
17 * List of option keys that need to be deleted when uninstalling the plugin.
18 *
19 * @var array
20 */
21 protected $options = [
22 'ep_host',
23 'ep_index_meta',
24 'ep_feature_settings',
25 'ep_version',
26 'ep_intro_shown',
27 'ep_last_sync',
28 'ep_need_upgrade_sync',
29 'ep_feature_requirement_statuses',
30 'ep_feature_auto_activated_sync',
31 'ep_hide_intro_shown_notice',
32 'ep_skip_install',
33 'ep_last_cli_index',
34 'ep_credentials',
35 'ep_prefix',
36 'ep_language',
37 'ep_bulk_setting',
38 'ep_last_index',
39
40 // Admin notices options
41 'ep_hide_host_error_notice',
42 'ep_hide_es_below_compat_notice',
43 'ep_hide_es_above_compat_notice',
44 'ep_hide_need_setup_notice',
45 'ep_hide_no_sync_notice',
46 'ep_hide_upgrade_sync_notice',
47 'ep_hide_auto_activate_sync_notice',
48 'ep_hide_using_autosuggest_defaults_notice',
49 'ep_hide_yellow_health_notice',
50 ];
51
52 /**
53 * List of transient keys that need to be deleted when uninstalling the plugin.
54 *
55 * @var array
56 */
57 protected $transients = [
58 'ep_es_info_response_code',
59 'ep_es_info_response_error',
60 '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 ];
67
68 /**
69 * Initialize uninstaller
70 *
71 * Perform some checks to make sure plugin can/should be uninstalled
72 *
73 * @since 1.7
74 * @return EP_Uninstaller
75 */
76 public function __construct() {
77
78 // Exit if accessed directly.
79 if ( ! defined( 'ABSPATH' ) ) {
80 $this->exit_uninstaller();
81 }
82
83 // EP_MANUAL_SETTINGS_RESET is used by the `settings-reset` WP-CLI command.
84 if ( ! defined( 'EP_MANUAL_SETTINGS_RESET' ) || ! EP_MANUAL_SETTINGS_RESET ) {
85 // Not uninstalling.
86 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) || ! WP_UNINSTALL_PLUGIN ) {
87 $this->exit_uninstaller();
88 }
89
90 // Not uninstalling this plugin.
91 if ( dirname( WP_UNINSTALL_PLUGIN ) !== dirname( plugin_basename( __FILE__ ) ) ) {
92 $this->exit_uninstaller();
93 }
94 }
95
96 // Uninstall ElasticPress.
97 $this->clean_options_and_transients();
98 }
99
100 /**
101 * Delete all the options in a single site context.
102 */
103 protected function delete_options() {
104 foreach ( $this->options as $option ) {
105 delete_option( $option );
106 }
107 }
108
109 /**
110 * Delete all the transients in a single site context.
111 */
112 protected function delete_transients() {
113 foreach ( $this->transients as $transient ) {
114 delete_transient( $transient );
115 }
116 }
117
118 /**
119 * Delete all transients of the Related Posts feature.
120 */
121 protected function delete_related_posts_transients() {
122 global $wpdb;
123
124 $related_posts_transients = $wpdb->get_col( "SELECT option_name FROM {$wpdb->prefix}options WHERE option_name LIKE '_transient_ep_related_posts_%'" );
125
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 );
130 }
131 }
132
133 /**
134 * Delete all transients of the total fields limit.
135 */
136 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 }
146 }
147
148 /**
149 * Cleanup options and transients
150 *
151 * Deletes ElasticPress options and transients.
152 *
153 * @since 4.2.0
154 */
155 protected function clean_options_and_transients() {
156 if ( is_multisite() ) {
157 foreach ( $this->options as $option ) {
158 delete_site_option( $option );
159 }
160 foreach ( $this->transients as $transient ) {
161 delete_site_transient( $transient );
162 }
163
164 $sites = get_sites();
165
166 foreach ( $sites as $site ) {
167 switch_to_blog( $site->blog_id );
168
169 $this->delete_options();
170 $this->delete_transients();
171 $this->delete_related_posts_transients();
172 $this->delete_total_fields_limit_transients();
173
174 restore_current_blog();
175 }
176 } else {
177 $this->delete_options();
178 $this->delete_transients();
179 $this->delete_related_posts_transients();
180 $this->delete_total_fields_limit_transients();
181 }
182 }
183
184 /**
185 * Cleanup options (deprecated, kept for documenting reasons.)
186 *
187 * @since 1.7
188 * @return void
189 * @see clean_options_and_transients
190 */
191 protected static function clean_options() {
192 _deprecated_function( __FUNCTION__, '4.2.0', '\EP_Uninstaller->clean_options_and_transients()' );
193 }
194
195 /**
196 * Exit uninstaller
197 *
198 * Gracefully exit the uninstaller if we should not be here
199 *
200 * @since 1.7
201 * @return void
202 */
203 protected function exit_uninstaller() {
204 status_header( 404 );
205 exit;
206 }
207 }
208
209 new EP_Uninstaller();
210