Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
100 lines (71 loc) · 2.33 KB
/
Copy pathuninstall.php
File metadata and controls
100 lines (71 loc) · 2.33 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
<?php
/*
* Uninstall - Remove all traces of the plugin from the WordPress install.
*/
// Check for Un-Install constant.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}
if ( is_multisite() ) {
global $wpdb;
// Store Network Site ID so we can get back later.
$current_blog = get_current_blog_id();
// Get a list of all Blog IDs, ignore network admin with ID of 1.
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = '{$wpdb->siteid}'
AND spam = '0'
AND deleted = '0'
AND archived = '0'
AND blog_id != '{$current_blog}'
");
foreach ( $blogs as $blog ) {
switch_to_blog( $blog->blog_id );
// Delete the Option we registered.
delete_option( 'kbte_plugin_options' );
delete_option( 'kebo_form_data' );
// Delete all Posts with our Custom Post Type
$args = array(
'post_type' => 'kbte_testimonials',
'post_status' => 'any',
'posts_per_page' => -1,
);
// Query for posts
$kbte_posts = new WP_Query( $args );
if ( ! isset( $kbte_posts ) || ! is_object( $kbte_posts->posts ) ) {
return;
}
// Loop each post and delete
foreach ( $kbte_posts->posts as $post ) {
// Ensure it is the correct post type
if ( 'kbte_testimonials' == $post->post_type ) {
wp_delete_post( $post->ID, true );
}
}
}
// Go back to Network Site
switch_to_blog( $current_blog );
} else {
// Delete the Option we registered.
delete_option( 'kbte_plugin_options' );
delete_option( 'kebo_form_data' );
// Delete all Posts with our Custom Post Type
$args = array(
'post_type' => 'kbte_testimonials',
'post_status' => 'any',
'posts_per_page' => -1,
);
// Query for posts
$kbte_posts = new WP_Query( $args );
if ( ! isset( $kbte_posts ) || false == $kbte_posts ) {
return;
}
// Loop each post and delete
foreach ( $kbte_posts->posts as $post ) {
// Ensure it is the correct post type
if ( 'kbte_testimonials' == $post->post_type ) {
wp_delete_post( $post->ID, true );
}
}
}