-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
98 lines (82 loc) · 1.9 KB
/
uninstall.php
File metadata and controls
98 lines (82 loc) · 1.9 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
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
<?php
/**
* This will be executed when the plugin is uninstalled.
*
* @package OneDesign
*/
declare( strict_types=1 );
namespace OneDesign;
// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Multisite loop for uninstalling from all sites.
*/
function multisite_uninstall(): void {
if ( ! is_multisite() ) {
uninstall();
return;
}
delete_network_plugin_data();
$site_ids = get_sites(
[
'fields' => 'ids',
'number' => 0,
]
) ?: [];
foreach ( $site_ids as $site_id ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog
if ( ! switch_to_blog( (int) $site_id ) ) {
continue;
}
uninstall();
restore_current_blog();
}
}
/**
* The (site-specific) uninstall function.
*/
function uninstall(): void {
delete_plugin_data();
}
/**
* Delete multisite network plugin data.
*/
function delete_network_plugin_data(): void {
$options = [
'onedesign_multisite_governing_site',
];
foreach ( $options as $option ) {
delete_site_option( $option );
}
}
/**
* Deletes meta, options, transients, etc.
*/
function delete_plugin_data(): void {
// First delete posts from brand sites.
$brand_site_post_ids = (array) get_option( 'onedesign_brand_site_post_ids', [] );
foreach ( $brand_site_post_ids as $post_id ) {
wp_delete_post( (int) $post_id, true );
}
$options = [
'onedesign_site_type',
'onedesign_consumer_api_key',
'onedesign_parent_site_url',
'onedesign_shared_sites',
'onedesign_brand_site_patterns',
'onedesign_child_site_public_key',
'onedesign_shared_templates',
'onedesign_brand_site_post_ids',
'onedesign_shared_patterns',
'onedesign_shared_template_parts',
'onedesign_shared_synced_patterns',
'onedesign_multisite_governing_site',
];
foreach ( $options as $option ) {
delete_option( $option );
}
}
// Run the uninstaller.
multisite_uninstall();