-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
130 lines (113 loc) · 3.1 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
//if uninstall/delete not called from WordPress exit
if( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();
else
pluginUninstall();
// Delete options array from options table
function pluginUninstall() {
global $wpdb;
global $tablename;
global $kit_post_type;
//Table to delete
$poststable = "wp_posts";
//Delete options for plugin
delete_option( 'glkit_options' );
//Delete Taxonomies before item
remove_custom_taxonomies();
//Remove custom posts
$kit_custom_posts = get_posts( array( 'post_type' => 'kit_item') );
foreach( $kit_custom_posts as $kit_post ) {
//Delete Meta Values
delete_post_meta($kit_post->ID, 'gift_sku' );
delete_post_meta($kit_post->ID, 'gift_price' );
delete_post_meta($kit_post->ID, 'gift_colour' );
delete_post_meta($kit_post->ID, 'gift_supplier' );
delete_post_meta($kit_post->ID, 'gift_url' );
delete_post_meta($kit_post->ID, 'gift_required' );
delete_post_meta($kit_post->ID, 'gift_description' );
// Delete's each post.
wp_delete_post($kit_post->ID, true);
// Set to False if you want to send them to Trash.
}
//Drop the table
$wpdb->query("DROP TABLE IF EXISTS $tablename");
}
function remove_custom_taxonomies() {
global $wp_taxonomies;
$taxonomies = array(
'gift_price'
);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => 0,
'child_of' => 0,
'get' => 'all',
'name__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core'
);
//ToDo Only returning attached taxonomies
$terms = get_terms( $taxonomies);
if($terms!=false)
{
foreach( $terms as $term ) {
//Delete term
wp_delete_term($term->term_id,'gift_price');
}
}
$taxonomies = array(
'gift_type'
);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => 0,
'child_of' => 0,
'get' => 'all',
'name__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core'
);
//ToDo Only returning attached taxonomies
$terms = get_terms( $taxonomies);
if($terms!=false)
{
foreach( $terms as $term ) {
//Delete term
wp_delete_term($term->term_id,'gift_type');
}
}
$taxonomy = 'gift_type';
if ( taxonomy_exists( $taxonomy))
{
$id = get_taxonomy($taxonomy);
unset( $wp_taxonomies[$taxonomy]);
}
$taxonomy = 'gift_price';
if ( taxonomy_exists( $taxonomy))
{
unset( $wp_taxonomies[$taxonomy]);
}
}