-
Notifications
You must be signed in to change notification settings - Fork 6
/
uninstall.php
112 lines (88 loc) · 2.25 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
<?php
/**
* Fired when the plugin is uninstalled.
*
* @link https://webberzone.com
* @since 1.0.0
*
* @package WZKB
* @subpackage WZKB/Uninstall
*/
// 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.
$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 ( $blogids as $blogid ) {
switch_to_blog( $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' );
}
// 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
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
}