-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuninstaller.php
More file actions
149 lines (120 loc) · 3.22 KB
/
uninstaller.php
File metadata and controls
149 lines (120 loc) · 3.22 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Fired when the plugin is uninstalled.
*
* @package WebberZone\Knowledge_Base
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
if ( is_multisite() ) {
// Get all blogs in the network and activate plugin on each one.
$wzkb_blogids = $wpdb->get_col( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
"
SELECT blog_id FROM $wpdb->blogs
WHERE archived = '0' AND spam = '0' AND deleted = '0'
"
);
foreach ( $wzkb_blogids as $wzkb_blogid ) {
switch_to_blog( $wzkb_blogid );
wzkb_delete_data();
restore_current_blog();
}
} else {
wzkb_delete_data();
}
/**
* Delete Data.
*
* @since 1.3.0
*/
function wzkb_delete_data() {
$settings = get_option( 'wzkb_settings' );
if ( ! empty( $settings['uninstall_options'] ) ) {
delete_option( 'wzkb_settings' );
}
if ( ! empty( $settings['uninstall_data'] ) ) {
$wzkbs = get_posts(
array(
'post_type' => 'wz_knowledgebase',
)
);
foreach ( $wzkbs as $wzkb ) {
wp_delete_post( $wzkb->ID );
}
wzkb_delete_taxonomy( 'wzkb_category' );
wzkb_delete_taxonomy( 'wzkb_tag' );
wzkb_delete_taxonomy( 'wzkb_product' );
// Delete rating data.
wzkb_delete_rating_data();
}
// Delete the cache.
wzkb_delete_cache();
}
/**
* Delete Custom Taxonomy.
*
* @since 1.3.0
*
* @param string $taxonomy Custom taxonomy.
*/
function wzkb_delete_taxonomy( $taxonomy ) {
global $wpdb;
$query = 'SELECT t.name, t.term_id
FROM ' . $wpdb->terms . ' AS t
INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy = "' . $taxonomy . '"';
$terms = $wpdb->get_results( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
foreach ( $terms as $term ) {
wp_delete_term( $term->term_id, $taxonomy );
}
}
/**
* Delete Cache.
*
* @since 1.8.0
*/
function wzkb_delete_cache() {
global $wpdb;
$sql = "
DELETE FROM {$wpdb->termmeta}
WHERE `meta_key` LIKE '_wzkb_cache_%'
";
$wpdb->query( $sql ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Delete Rating Data.
*
* Removes all rating-related post meta from the database.
*
* @since 3.0.0
*/
function wzkb_delete_rating_data() {
global $wpdb;
// Array of rating meta keys to delete.
$rating_meta_keys = array(
'_wzkb_rating_total',
'_wzkb_rating_sum',
'_wzkb_rating_positive',
'_wzkb_ratings',
'_wzkb_rating_ips',
'_wzkb_rating_user_ids',
'_wzkb_rating_feedback',
);
// Delete all rating meta for each key.
foreach ( $rating_meta_keys as $meta_key ) {
//phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
$meta_key
)
);
}
// Delete rating cache.
wp_cache_delete( 'wzkb_rating_global_mean_binary', 'wzkb_rating' );
wp_cache_delete( 'wzkb_rating_global_mean_scale', 'wzkb_rating' );
}