-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathuninstall.php
More file actions
56 lines (47 loc) · 1.39 KB
/
uninstall.php
File metadata and controls
56 lines (47 loc) · 1.39 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
<?php
/**
* Plugin uninstaller logic.
*
* @package optimization-detective
* @since 0.1.0
*/
declare( strict_types = 1 );
// If uninstall.php is not called by WordPress, bail.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit; // @codeCoverageIgnore
}
require_once __DIR__ . '/storage/class-od-url-metrics-post-type.php';
$od_delete_site_data = static function (): void {
// Delete all URL Metrics posts for the current site.
OD_URL_Metrics_Post_Type::delete_all_posts();
wp_unschedule_hook( OD_URL_Metrics_Post_Type::GC_CRON_EVENT_NAME );
// Clear out options and transients.
delete_option( 'od_rest_api_unavailable' );
delete_transient( 'od_rest_api_health_check_response' );
};
$od_delete_site_data();
/*
* For a multisite install, delete the URL Metrics for all other sites (however, this is limited to 100 sites to avoid memory limit
* and timeout problems in large scale networks).
*/
if ( is_multisite() ) {
$od_site_ids = get_sites(
array(
'fields' => 'ids',
'number' => 100,
'update_site_cache' => false,
'update_site_meta_cache' => false,
)
);
// Skip iterating over self.
$od_site_ids = array_diff(
$od_site_ids,
array( get_current_blog_id() )
);
// Delete all other blogs' URL Metrics posts.
foreach ( $od_site_ids as $od_site_id ) {
switch_to_blog( $od_site_id );
$od_delete_site_data();
restore_current_blog();
}
}