-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
123 lines (75 loc) · 2.83 KB
/
Copy pathuninstall.php
File metadata and controls
123 lines (75 loc) · 2.83 KB
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
<?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_p6_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');
}
}
$cb_p6 = new cb_dud_object;
// Include internal vars from file:
// Get options
$cb_p6->opt=get_option($cb_p6->internal['prefix'].'options');
if($cb_p6->opt['delete_options_on_uninstall']=='yes')
{
$wpdb->query( $wpdb->prepare( "DELETE FROM " . $wpdb->options . " WHERE option_name LIKE %s", $cb_p6->internal['id'] . '_%' ) );
}
if($cb_p6->opt['delete_data_on_uninstall']=='yes')
{
foreach($cb_p6->internal['tables'] as $key => $value)
{
$safe_key = preg_replace( '/[^a-zA-Z0-9_]/', '', $key );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . $cb_p6->internal['id'] . "_" . $safe_key );
}
foreach($cb_p6->internal['meta_tables'] as $key => $value)
{
$safe_key = preg_replace( '/[^a-zA-Z0-9_]/', '', $key );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . $cb_p6->internal['id'] . "_" . $safe_key );
}
// Remove wordpress posts
// Get posts first:
$results = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", $cb_p6->internal['id'] . '_ticket' ), ARRAY_A );
foreach($results as $key => $value)
{
$post_id = intval( $results[$key]['ID'] );
// Delete post meta
$wpdb->query( $wpdb->prepare( "DELETE FROM " . $wpdb->postmeta . " WHERE post_id = %d", $post_id ) );
// Delete post
$wpdb->query( $wpdb->prepare( "DELETE FROM " . $wpdb->posts . " WHERE ID = %d", $post_id ) );
}
// Delete custom taxonomy
// Delete terms
$taxonomy_name = $cb_p6->internal['id'] . '_support';
$wpdb->query( $wpdb->prepare( "
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 = %s
) as T
);
", $taxonomy_name ) );
// Delete taxonomies
$wpdb->query( $wpdb->prepare( "DELETE FROM " . $wpdb->term_taxonomy . " WHERE taxonomy = %s", $taxonomy_name ) );
}
?>