-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
95 lines (85 loc) · 3.09 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
<?php
/***********************************************************************************************************************
* Inesonic SpeedSentry - Site Performance Monitoring For Wordpress
*
* Copyright 2021, Inesonic, LLC
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
***********************************************************************************************************************
* \file uninstall.php
*
* Uninstaller.
*/
/**
* Small class that uninstalls this plug-in. Coded as a class to help manage the use of the SPL autoloader.
*/
class InesonicUninstaller {
/**
* The namespace that we need to perform auto-loading for.
*/
const PLUGIN_NAMESPACE = 'Inesonic\\SpeedSentry\\';
/**
* The plug-in include path.
*/
const INCLUDE_PATH = __DIR__ . '/include/';
/**
* Options prefix.
*/
const OPTIONS_PREFIX = 'inesonic_speedsentry';
/**
* Static method triggered to uninstall this plug-in.
*/
public static function uninstall() {
spl_autoload_register(array(self::class, 'autoloader'));
$slug = dirname(plugin_basename(__FILE__));
$options = new Inesonic\SpeedSentry\Options(self::OPTIONS_PREFIX, $slug);
$options->plugin_uninstalled();
}
/**
* Constructor
*/
public function __construct() {
}
/**
* Autoloader callback.
*
* \param[in] class_name The name of this class.
*/
static public function autoloader($class_name) {
if (!class_exists($class_name) && str_starts_with($class_name, self::PLUGIN_NAMESPACE)) {
$class_basename = str_replace(self::PLUGIN_NAMESPACE, '', $class_name);
$filepath = self::INCLUDE_PATH;
$last_was_lower = false;
for ($i=0 ; $i<strlen($class_basename) ; ++$i) {
$c = $class_basename[$i];
if (ctype_upper($c)) {
if ($last_was_lower) {
$filepath .= '-' . strtolower($c);
$last_was_lower = false;
} else {
$filepath .= strtolower($c);
}
} else {
$filepath .= $c;
$last_was_lower = true;
}
}
$filepath .= '.php';
if (file_exists($filepath)) {
include $filepath;
}
}
}
};
if (defined('WP_UNINSTALL_PLUGIN')) {
InesonicUninstaller::uninstall();
}