-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathuninstall.php
112 lines (88 loc) · 2.84 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
/**
* This will fire when the plugin is uninstalled, removing all options and post types (hopefully).
*
* @package LDDBD
* @author LDD Web Design <info@lddwebdesign.com>
* @license GPL-2.0+
* @link http://lddwebdesign.com
* @copyright 2014 LDD Consulting, Inc
*
*/
if (!defined('WP_UNINSTALL_PLUGIN'))
die;
require_once(dirname(__FILE__) . '/ldd-directory-lite.php');
/**
* Collect and then delete all attachments
*/
function ldl_uninstall_attachments() {
global $wpdb;
$query = sprintf("
SELECT ID
FROM `%s`
WHERE post_type = '%s'
AND post_status NOT IN ( 'auto-draft', 'inherit' )
", $wpdb->posts, LDDLITE_POST_TYPE);
$post_ids = $wpdb->get_col($query);
if (!$post_ids)
return;
$attachments = new WP_Query(array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'any',
'post_parent__in' => $post_ids,
'no_found_rows' => true,
'fields' => 'ids'
));
$attachments = $attachments->posts;
if ($attachments) {
foreach ($attachments as $attachment) {
wp_delete_attachment( $attachment );
}
}
}
/**
* Delete everything with as little of a footprint as we can muster, to try and ensure this process succeeds.
*/
function ldl_uninstall_posts() {
global $wpdb;
// Delete postmeta and posts
$wpdb->query(sprintf("DELETE FROM %s WHERE post_id IN ( SELECT id FROM %s WHERE post_type = '%s' ) ", $wpdb->postmeta, $wpdb->posts, LDDLITE_POST_TYPE));
$wpdb->query(sprintf("DELETE FROM %s WHERE post_type = '%s'", $wpdb->posts, LDDLITE_POST_TYPE));
}
/**
* Deletes all taxonomy data
*/
function ldl_uninstall_taxonomies() {
global $wpdb;
// Loop through our taxonomies and destroy
foreach (array(LDDLITE_TAX_CAT, LDDLITE_TAX_TAG) as $taxonomy) {
$results = $wpdb->get_results(sprintf("
SELECT t.*, tt.*
FROM $wpdb->terms AS t
INNER JOIN $wpdb->term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('%s')
ORDER BY t.name ASC
", $taxonomy));
if (!$results)
continue;
foreach ($results as $term) {
$wpdb->delete($wpdb->term_taxonomy, array('term_taxonomy_id' => $term->term_taxonomy_id));
$wpdb->delete($wpdb->terms, array('term_id' => $term->term_id));
}
$wpdb->delete($wpdb->term_taxonomy, array('taxonomy' => $taxonomy), array('%s'));
}
}
/**
* Uninstall
*/
ldl_uninstall_attachments();
ldl_uninstall_posts();
ldl_uninstall_taxonomies();
delete_option('lddlite_settings');
delete_option('lddlite_version');
delete_option('lddlite_imported_from_original');
// mdd?\s?\(
// test: md() mdd()
// Never ship a release with either of those two commands anywhere but here.