Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/WPRocketUninstall.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
use WP_Rocket\Dependencies\BerlinDB\Database\Table;
4
+
use WP_Rocket\Engine\Optimization\RUCSS\Database\Tables\UsedCSS;
5
+
use WP_Rocket\Engine\Preload\Database\Tables\Cache;
6
+
use WP_Rocket\Engine\Media\AboveTheFold\Database\Tables\AboveTheFold;
7
+
use WP_Rocket\Engine\Optimization\LazyRenderContent\Database\Table\LazyRenderContent;
8
+
use WP_Rocket\Engine\Media\PreloadFonts\Database\Table\PreloadFonts;
9
+
use WP_Rocket\Engine\Media\PreconnectExternalDomains\Database\Table\PreconnectExternalDomains;
10
+
11
+
/**
12
+
* Manages the deletion of WP Rocket data and files on uninstall.
13
+
*/
14
+
class WPRocketUninstall {
15
+
16
+
/**
17
+
* Path to the cache folder.
18
+
*
19
+
* @var string
20
+
*/
21
+
private $cache_path;
22
+
23
+
/**
24
+
* Path to the config folder.
25
+
*
26
+
* @var string
27
+
*/
28
+
private $config_path;
29
+
30
+
/**
31
+
* WP Rocket options.
32
+
*
33
+
* @var array
34
+
*/
35
+
private $options = [
36
+
'wp_rocket_settings',
37
+
'rocket_analytics_notice_displayed',
38
+
'rocketcdn_user_token',
39
+
'rocketcdn_process',
40
+
'wp_rocket_hide_deactivation_form',
41
+
'wp_rocket_last_base_url',
42
+
'wp_rocket_no_licence',
43
+
'wp_rocket_last_option_hash',
44
+
'wp_rocket_debug',
45
+
'wp_rocket_rocketcdn_old_url',
46
+
'plugin_family_dismiss_promote_imagify',
47
+
];
48
+
49
+
/**
50
+
* WP Rocket transients.
51
+
*
52
+
* @var array
53
+
*/
54
+
private $transients = [
55
+
'wp_rocket_customer_data',
56
+
'rocket_notice_missing_tags',
57
+
'rocket_clear_cache',
58
+
'rocket_check_key_errors',
59
+
'rocket_send_analytics_data',
60
+
'rocket_critical_css_generation_process_running',
61
+
'rocket_critical_css_generation_process_complete',
62
+
'rocket_critical_css_generation_triggered',
63
+
'rocketcdn_status',
64
+
'rocketcdn_pricing',
65
+
'rocketcdn_purge_cache_response',
66
+
'rocket_cloudflare_ips',
67
+
'rocket_cloudflare_is_api_keys_valid',
68
+
'rocket_preload_triggered',
69
+
'rocket_preload_complete',
70
+
'rocket_preload_complete_time',
71
+
'rocket_preload_errors',
72
+
'rocket_database_optimization_process',
73
+
'rocket_database_optimization_process_complete',
74
+
'rocket_hide_deactivation_form',
75
+
'wpr_preload_running',
76
+
'rocket_preload_as_tables_count',
77
+
'wpr_dynamic_lists',
78
+
'wpr_dynamic_lists_delayjs',
79
+
'rocket_domain_changed',
80
+
'wp_rocket_rucss_errors_count',
81
+
'wpr_dynamic_lists_incompatible_plugins',
82
+
'rocket_divi_notice',
83
+
'rocket_saas_processing',
84
+
'rocket_mod_pagespeed_enabled',
85
+
'wp_rocket_pricing',
86
+
'wp_rocket_pricing_timeout',
87
+
'wp_rocket_pricing_timeout_active',
88
+
'rocket_get_refreshed_fragments_cache',
89
+
'rocket_preload_previous_requests_durations',
90
+
'rocket_preload_check_duration',
91
+
'wpr_user_information_timeout_active',
92
+
'wpr_user_information_timeout',
93
+
'rocket_fonts_data_collection',
94
+
'wpr_global_score_data',
95
+
];
96
+
97
+
/**
98
+
* WP Rocket scheduled events.
99
+
*
100
+
* @var array
101
+
*/
102
+
private $events = [
103
+
'rocket_purge_time_event',
104
+
'rocket_database_optimization_time_event',
105
+
'rocket_cache_dir_size_check',
106
+
'rocketcdn_check_subscription_status_event',
107
+
'rocket_cron_deactivate_cloudflare_devmode',
108
+
'rocket_saas_clean_rows_time_event',
109
+
'rocket_saas_on_submit_jobs',
110
+
'rocket_saas_pending_jobs',
111
+
'rocket_remove_saas_failed_jobs',
112
+
'rocket_performance_hints_cleanup',
113
+
'action_scheduler_run_queue_rucss',
114
+
'rocket_update_dynamic_lists',
115
+
'rocket_preload_clean_rows_time_event',
116
+
'rocket_preload_process_pending',
117
+
'rocket_preload_revert_old_failed_rows',
118
+
];
119
+
120
+
/**
121
+
* WP Rocket cache directories.
122
+
*
123
+
* @var array
124
+
*/
125
+
private $cache_dirs = [
126
+
'wp-rocket',
127
+
'min',
128
+
'busting',
129
+
'critical-css',
130
+
'used-css',
131
+
'fonts',
132
+
'background-css',
133
+
];
134
+
135
+
/**
136
+
* WP Rocket Post MetaData Entries
137
+
*
138
+
* @var array
139
+
*/
140
+
private $post_meta = [
141
+
'minify_css',
142
+
'minify_js',
143
+
'cdn',
144
+
'lazyload',
145
+
'lazyload_iframes',
146
+
'async_css',
147
+
'defer_all_js',
148
+
'delay_js',
149
+
'remove_unused_css',
150
+
'lazyload_css_bg_img',
151
+
];
152
+
153
+
/**
154
+
* Tables instances
155
+
*
156
+
* @var array
157
+
*/
158
+
private $tables;
159
+
160
+
/**
161
+
* Constructor.
162
+
*
163
+
* @param string $cache_path Path to the cache folder.
164
+
* @param string $config_path Path to the config folder.
165
+
* @param array $tables Array of tables to be dropped.
166
+
*/
167
+
public function __construct(
168
+
$cache_path,
169
+
$config_path,
170
+
$tables
171
+
) {
172
+
$this->cache_path = trailingslashit( $cache_path );
173
+
$this->config_path = $config_path;
174
+
$this->tables = $tables;
175
+
}
176
+
177
+
/**
178
+
* Deletes all plugin data and files on uninstall.
179
+
*
180
+
* @since 3.5.2
181
+
*
182
+
* @return void
183
+
*/
184
+
public function uninstall() {
185
+
$this->delete_plugin_data();
186
+
$this->delete_cache_files();
187
+
$this->delete_config_files();
188
+
189
+
foreach ( $this->tables as $table ) {
190
+
$this->delete_table( $table );
191
+
}
192
+
}
193
+
194
+
/**
195
+
* Deletes a table
196
+
*
197
+
* @param Table $table Table instance.
198
+
*
199
+
* @return void
200
+
*/
201
+
private function delete_table( $table ) {
202
+
if ( $table->exists() ) {
203
+
$table->uninstall();
204
+
}
205
+
206
+
if ( ! is_multisite() ) {
207
+
return;
208
+
}
209
+
210
+
foreach ( get_sites( [ 'fields' => 'ids' ] ) as $site_id ) {
211
+
switch_to_blog( $site_id );
212
+
213
+
if ( $table->exists() ) {
214
+
$table->uninstall();
215
+
}
216
+
217
+
restore_current_blog();
218
+
}
219
+
}
220
+
221
+
/**
222
+
* Deletes WP Rocket options, transients and events.
223
+
*
224
+
* @since 3.5.2
225
+
*
226
+
* @return void
227
+
*/
228
+
private function delete_plugin_data() {
229
+
delete_site_transient( 'wp_rocket_update_data' );
230
+
231
+
// Delete all user meta related to WP Rocket.
232
+
delete_metadata( 'user', '', 'rocket_boxes', '', true );
233
+
234
+
// Delete all post meta related to WP Rocket.
235
+
foreach ( $this->post_meta as $post_meta ) {
236
+
delete_post_meta_by_key( "_rocket_exclude_{$post_meta}" );
237
+
}
238
+
239
+
array_walk( $this->transients, 'delete_transient' );
240
+
array_walk( $this->options, 'delete_option' );
241
+
242
+
foreach ( $this->events as $event ) {
243
+
if ( ! wp_next_scheduled( $event ) ) {
244
+
continue;
245
+
}
246
+
wp_clear_scheduled_hook( $event );
247
+
}
248
+
}
249
+
250
+
/**
251
+
* Deletes all WP Rocket cache files.
252
+
*
253
+
* @since 3.5.2
254
+
*
255
+
* @return void
256
+
*/
257
+
private function delete_cache_files() {
258
+
foreach ( $this->cache_dirs as $dir ) {
259
+
$this->delete( $this->cache_path . $dir );
260
+
}
261
+
}
262
+
263
+
/**
264
+
* Deletes all WP Rocket config files.
265
+
*
266
+
* @since 3.5.2
267
+
*
268
+
* @return void
269
+
*/
270
+
private function delete_config_files() {
271
+
$this->delete( $this->config_path );
272
+
}
273
+
274
+
/**
275
+
* Recursively deletes files and directories.
276
+
*
277
+
* @since 3.5.2
278
+
*
279
+
* @param string $file Path to file or directory.
280
+
*/
281
+
private function delete( $file ) {
282
+
if ( ! is_dir( $file ) ) {
283
+
wp_delete_file( $file );
284
+
return;
285
+
}
286
+
287
+
try {
288
+
$iterator = new RecursiveIteratorIterator(
289
+
new RecursiveDirectoryIterator( $file, FilesystemIterator::SKIP_DOTS ),
290
+
RecursiveIteratorIterator::CHILD_FIRST
291
+
);
292
+
} catch ( UnexpectedValueException $e ) {
293
+
return;
294
+
}
295
+
296
+
foreach ( $iterator as $item ) {
297
+
if ( $item->isDir() ) {
298
+
@rmdir( $item ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
299
+
300
+
continue;
301
+
}
302
+
303
+
wp_delete_file( $item );
304
+
}
305
+
306
+
@rmdir( $file ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
307
+
}
308
+
}
309
+