forked from deckerweb/toolbar-extras-mainwp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
132 lines (96 loc) · 2.65 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
// uninstall
/**
* Prevent direct access to this file.
*
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Sorry, you are not allowed to access this file directly.' );
}
/**
* If uninstall not called from WordPress, exit.
*
* @since 1.0.0
*
* @uses WP_UNINSTALL_PLUGIN
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
/**
* Various user checks.
*
* @since 1.0.0
*
* @uses is_user_logged_in()
* @uses current_user_can()
* @uses wp_die()
*/
if ( ! is_user_logged_in() ) {
wp_die(
__( 'You must be logged in to run this script.', 'toolbar-extras-mainwp' ),
__( 'Toolbar Extras for MainWP', 'toolbar-extras-mainwp' ),
array( 'back_link' => TRUE )
);
} // end if
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die(
__( 'You do not have permission to run this script.', 'toolbar-extras-mainwp' ),
__( 'Toolbar Extras for MainWP', 'toolbar-extras-mainwp' ),
array( 'back_link' => TRUE )
);
} // end if
/**
* Delete all options and transients from the 'options' table in DB.
*
* @since 1.0.0
*
* @uses delete_option()
*/
function ddw_tbexmwp_delete_options_transients() {
/** Delete all options */
delete_option( 'tbex-options-mainwp' );
delete_option( 'tbexmwp-addon-version' );
} // end function
/**
* Delete our options array (settings field) from the database.
* Note: Respects Multisite setups and single installs.
*
* @since 1.0.0
*
* @link https://leaves-and-love.net/blog/making-plugin-multisite-compatible/
*
* @uses ddw_tbex_delete_options_transients()
*
* @param array $blogs
* @param int $blog
*
* @global $wpdb
*/
/** First, check for Multisite, if yes, delete options on a per site basis */
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
global $wpdb;
if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
$site_ids = get_sites( array( 'fields' => 'ids', 'network_id' => get_current_network_id() ) );
foreach ( $site_ids as $site_id ) {
switch_to_blog( $site_id );
/** Delete our stuff for Multisite sub-sites */
ddw_tbexmwp_delete_options_transients();
restore_current_blog();
} // end foreach
} else {
$sites = wp_get_sites( array( 'limit' => 0 ) );
foreach ( $sites as $site ) {
switch_to_blog( $site[ 'blog_id' ] );
/** Delete our stuff for Multisite sub-sites */
ddw_tbexmwp_delete_options_transients();
restore_current_blog();
} // end foreach
} // end if
} else { /** Otherwise, delete options from main options table */
/** Delete our stuff */
ddw_tbexmwp_delete_options_transients();
} // end if