-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
72 lines (59 loc) · 1.6 KB
/
uninstall.php
File metadata and controls
72 lines (59 loc) · 1.6 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
<?php
/**
* Ensemble Uninstaller
*
* @package Ensemble\Core
* @copyright Copyright (c) 2018, Drew Jaynes
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
global $wpdb;
//
// Roles & Capabilities
//
wp_roles()->remove_role( 'ensemble_director' );
//
// Custom Tables
//
$table_segments = array(
'ensemble_contests',
'ensemble_venues',
);
// Drop the tables (no turning back now!).
foreach ( $table_segments as $table_segment ) {
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . $table_segment );
}
//
// Taxonomies, Terms, & Term meta
//
$taxonomies = array(
'ensemble_unit',
'ensemble_class',
'ensemble_season'
);
foreach ( $taxonomies as $taxonomy ) {
// Get the terms.
$terms = $wpdb->get_results(
$wpdb->prepare(
"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 terms were found, loop through and delete the records.
if ( $terms ) {
foreach ( $terms 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
) );
}
}
// Delete the taxonomy.
$wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $taxonomy ), array( '%s' ) );
}
// Delete leftover/orphaned term meta.
if ( ! empty( $wpdb->termmeta ) ) {
$wpdb->query( "DELETE termmeta FROM {$wpdb->termmeta} termmeta LEFT JOIN {$wpdb->term_taxonomy} tt ON termmeta.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
}