-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathuninstall.php
executable file
·144 lines (107 loc) · 3.06 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
133
134
135
136
137
138
139
140
141
142
143
144
<?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' ),
__( 'Toolbar Extras', 'toolbar-extras' ),
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' ),
__( 'Toolbar Extras', 'toolbar-extras' ),
array( 'back_link' => TRUE )
);
} // end if
/**
* Delete all options and transients from the 'options' table in DB.
*
* @since 1.0.0
* @since 1.4.0 Added new option & transient.
*
* @uses delete_option()
* @uses delete_site_transient()
* @uses delete_transient()
*/
function ddw_tbex_delete_options_transients() {
/** Delete all options */
delete_option( 'tbex-options-general' );
delete_option( 'tbex-options-tweaks' );
delete_option( 'tbex-options-development' );
delete_option( 'tbex-plugin-version' );
delete_option( 'tbex-plugin-old-setup' );
/** Delete all transients */
delete_site_transient( 'tbex-notice-plugins-welcome' );
delete_site_transient( 'tbex-notice-welcome' );
delete_transient( 'tbex-notice-plugin-first-rating' );
} // end function
/**
* Delete our options array (settings field) from the database.
* Note: Respects Multisite setups and single installs.
*
* @since 1.0.0
* @since 1.3.2 Updated to newer Multisite approach.
*
* @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_tbex_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_tbex_delete_options_transients();
restore_current_blog();
} // end foreach
} // end if
} else { /** Otherwise, delete options from main options table */
/** Delete our stuff */
ddw_tbex_delete_options_transients();
} // end if