-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathuninstall.php
60 lines (51 loc) · 1.4 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
<?php
/**
* Fired when the plugin is uninstalled.
*
* @package SimpleCalendar
*/
// Exit if not uninstalling from WordPress.
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit();
}
// Get user options whether to delete settings and/or data.
$settings = get_option('simple-calendar_settings_advanced');
if (isset($settings['installation']['delete_settings'])) {
$delete_settings = 'yes' == $settings['installation']['delete_settings'] ? true : false;
} else {
$delete_settings = false;
}
if (isset($settings['installation']['erase_data'])) {
$erase_data = 'yes' == $settings['installation']['erase_data'] ? true : false;
} else {
$erase_data = false;
}
global $wpdb;
// Delete settings.
if ($delete_settings === true || $erase_data === true) {
$wpdb->query(
"
DELETE FROM $wpdb->options WHERE option_name LIKE '%simple-calendar%';
"
);
}
// Delete calendar data.
if ($erase_data === true) {
// Delete calendar posts.
$wpdb->query(
"
DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'calendar' );
"
);
// Delete calendar postmeta.
$wpdb->query("
DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;
");
// Delete calendar terms.
$terms = get_terms(['calendar_category', 'calendar_feed', 'calendar_type']);
if (!empty($terms) && is_array($terms)) {
foreach ($terms as $term) {
wp_delete_term($term->term_id, $term->taxonomy);
}
}
}