-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
121 lines (72 loc) · 2.6 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
<?php
// if uninstall.php is not called by WordPress, die
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
global $wpdb;
// Create dud object for loading options and internal vars:
class cb_dud_object {
public $internal = array(
// Holds internal and generated vars. Never saved.
);
public $opt = array(
// Holds internal and generated vars. Never saved.
);
public $hardcoded = array(
// Holds hardcoded vars. Never saved.
);
public function __construct()
{
require_once('core/includes/default_internal_vars.php');
require_once('plugin/includes/default_internal_vars.php');
require_once('plugin/includes/hardcoded_vars.php');
}
}
$PLUGINPREFIX = new cb_dud_object;
// Include internal vars from file:
// Get options
$PLUGINPREFIX->opt=get_option($PLUGINPREFIX->internal['prefix'].'options');
if($PLUGINPREFIX->opt['delete_options_on_uninstall']=='yes')
{
$wpdb->query( "DELETE FROM ".$wpdb->options." WHERE option_name LIKE '".$PLUGINPREFIX->internal['id']."_%';");
}
if($PLUGINPREFIX->opt['delete_data_on_uninstall']=='yes')
{
foreach($PLUGINPREFIX->internal['tables'] as $key => $value)
{
$wpdb->query( "DROP TABLE IF EXISTS ".$wpdb->prefix.$PLUGINPREFIX->internal['id']."_".$key.";");
}
foreach($PLUGINPREFIX->internal['meta_tables'] as $key => $value)
{
$wpdb->query( "DROP TABLE IF EXISTS ".$wpdb->prefix.$PLUGINPREFIX->internal['id']."_".$key.";");
}
// Remove wordpress posts
// Get posts first:
$results = $wpdb->get_results( "SELECT ID FROM ".$wpdb->posts." WHERE post_type = '".$PLUGINPREFIX->internal['id']."_ticket';",ARRAY_A);
foreach($results as $key => $value)
{
$post_id = $results[$key]['ID'];
// Delete post meta
$wpdb->query( "DELETE FROM ".$wpdb->postmeta." WHERE post_id = '".$post_id."';");
// Delete post
$wpdb->query( "DELETE FROM ".$wpdb->posts." WHERE ID = '".$post_id."';");
}
// Delete custom taxonomy
// Delete terms
$wpdb->query( "
DELETE FROM
".$wpdb->terms."
WHERE term_id IN
( SELECT * FROM (
SELECT ".$wpdb->terms.".term_id
FROM ".$wpdb->terms."
JOIN ".$wpdb->term_taxonomy."
ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
WHERE taxonomy = '".$PLUGINPREFIX->internal['id']."_support'
) as T
);
" );
// Delete taxonomies
$wpdb->query( "DELETE FROM ".$wpdb->term_taxonomy." WHERE taxonomy = '".$PLUGINPREFIX->internal['id']."_support'" );
}
?>