forked from ThemeFuse/Unyson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
91 lines (74 loc) · 1.78 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
<?php if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) die('Forbidden');
/**
* Remove all plugin and extensions data
* Search in all extensions and include the uninstall.php file
*
* WARNING!
* The uninstall.php file must not contain:
* <?php if ( !defined( 'FW' ) ) die('Forbidden');
* because the framework is not loaded at this point, use:
* <?php if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) die('Forbidden');
*/
function _include_file_isolated($path) {
include $path;
}
class FW_Plugin_Uninstall
{
/**
* All extensions with uninstall.php
* @var array
*/
private $extensions = array();
public function __construct()
{
$this->read_extensions(
dirname(__FILE__) .'/framework/extensions',
$this->extensions
);
{
/** @var wpdb $wpdb */
global $wpdb;
$this->uninstall();
if ( is_multisite() ) { // http://wordpress.stackexchange.com/a/80351/60424
$original_blog_id = get_current_blog_id();
foreach (
$wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" )
as $blog_id
) {
switch_to_blog( $blog_id );
$this->uninstall();
}
switch_to_blog( $original_blog_id );
}
}
}
private function read_extensions($dir, &$extensions)
{
$ext_dirs = glob($dir .'/*', GLOB_ONLYDIR);
if (empty($ext_dirs)) {
return;
}
foreach ($ext_dirs as $ext_dir) {
if (
file_exists($ext_dir .'/manifest.php')
&&
file_exists($ext_dir .'/uninstall.php')
) {
$extensions[ basename($ext_dir) ] = $ext_dir .'/uninstall.php';
}
$this->read_extensions($ext_dir .'/extensions', $extensions);
}
}
private function uninstall()
{
// Remove framework data
{
// ...
}
// Remove extensions data
foreach ($this->extensions as $uninstall_file) {
_include_file_isolated($uninstall_file);
}
}
}
new FW_Plugin_Uninstall();