forked from WebberZone/knowledgebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
executable file
·88 lines (67 loc) · 1.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
<?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.
$blog_ids = $wpdb->get_col( "
SELECT blog_id FROM $wpdb->blogs
WHERE archived = '0' AND spam = '0' AND deleted = '0'
" );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
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 ( $settings['uninstall_options'] ) {
delete_option( 'wzkb_settings' );
}
if ( $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 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 );
foreach ( $terms as $term ) {
wp_delete_term( $term->term_id, $taxonomy );
}
}