-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall.php
61 lines (49 loc) · 1.19 KB
/
uninstall.php
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
<?php
/**
* Summary (no period for file headers)
*
* Description. (use period)
*
* @link URL
*
* @package simple-metadata-lifecycle
* @subpackage XXXXXX/XXXXXX
* @since x.x.x (when the file was introduced)
*/
/**
* Fired when plugin is uninstalled.
*
* @since 0.1
*
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
//get all the sites for multisite, if not a multisite, set blog id to 1
if (is_multisite()) {
$blogs_ids = get_sites();
} else {
$blogs_ids = [1];
}
foreach( $blogs_ids as $b ) {
//if multisite, each iteration changes site
if ( is_multisite() ) {
switch_to_blog( $b->blog_id );
}
//get all the options from database
$all_options = wp_load_alloptions();
$plugin_options = [];
//extract plugin options from all options
foreach ( $all_options as $name => $value ) {
if ( stristr( $name, 'src_net_' ) || stristr( $name, 'src_freeze_' ) || stristr( $name, 'src_time_' )) {
$plugin_options[ $name ] = $value;
}
}
//delete plugin options
foreach ( $plugin_options as $key => $value ) {
if ( get_option( $key ) || get_option( $key, 'nonex' ) !== 'nonex' ) {
delete_option( $key );
}
}
}