-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall.php
88 lines (79 loc) · 1.81 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
<?php
/**
* Fired when the plugin is uninstalled.
*
* @since 1.0.0
*
* @package VaakyHighlighter
*/
// If uninstall not called from WordPress, then exit.
if (!defined('WP_UNINSTALL_PLUGIN'))
{
exit();
}
$currentNetworkId = get_current_network_id();
deleteConfigOptions($currentNetworkId);
// If Multisite is enabled, then uninstall the plugin on every site.
if (is_multisite())
{
// Permission check
if (!current_user_can('manage_network_plugins'))
{
wp_die('You don\'t have proper authorization to delete a plugin!');
}
/**
* Delete the Network options
*/
deleteNetworkOptions($currentNetworkId);
/**
* Delete the site specific options
*/
foreach (get_sites(['fields' => 'ids']) as $blogId)
{
switch_to_blog($blogId);
// Site specific uninstall code starts here...
deleteOptions();
restore_current_blog();
}
}
else
{
// Permission check
if (!current_user_can('activate_plugins'))
{
wp_die('You don\'t have proper authorization to delete a plugin!');
}
deleteOptions();
}
/**
* Delete the plugin's configuration data.
*
* @since 1.0.0
* @param int $currentNetworkId
* @return void
*/
function deleteConfigOptions($currentNetworkId)
{
delete_network_option($currentNetworkId, 'vaaky-highlighter-configuration');
}
/**
* Delete the plugin's network options.
*
* @since 1.0.0
* @param int $currentNetworkId
* @return void
*/
function deleteNetworkOptions($currentNetworkId)
{
delete_network_option($currentNetworkId, 'vaaky-highlighter-network-general');
}
/**
* Delete the plugin's options.
*
* @since 1.0.0
*/
function deleteOptions()
{
delete_option(VAAKY_HIGHLIGHTER_SLUG . '-settings-option');
delete_option(VAAKY_HIGHLIGHTER_SLUG . '-configuration');
}