-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
91 lines (61 loc) · 1.85 KB
/
uninstall.php
File metadata and controls
91 lines (61 loc) · 1.85 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
<?php
namespace CupCode\MyWooCommerce;
defined('WP_UNINSTALL_PLUGIN') or die('No script kiddies please!');
define('CC_MYWC_PLUGIN_SLUG', 'cupcode_mywc');
define('CC_MYWC_PLUGIN_PATH', plugin_dir_path(__FILE__));
$should_wipe = get_option(CC_MYWC_PLUGIN_SLUG . '_settings');
/**
* If user selected wipe, so wipe!
*/
if ($should_wipe['dc_all']) {
delete_option(CC_MYWC_PLUGIN_SLUG . '_settings');
delete_option(CC_MYWC_PLUGIN_SLUG . '_attribute_endpoint');
wipe_selectable_attributes();
wipe_user_attributes();
} else {
if ($should_wipe['dc_settings']){
delete_option(CC_MYWC_PLUGIN_SLUG . '_settings');
delete_option(CC_MYWC_PLUGIN_SLUG . '_attribute_endpoint');
}
if ($should_wipe['dc_attributes']) {
wipe_selectable_attributes();
wipe_user_attributes();
}
}
/**
* Wipes all posts and related data such as postmeta and related taxonomy of '_sa' post type
* @since 0.1.0
*/
function wipe_selectable_attributes()
{
global $wpdb;
$wpdb->query("DELETE p,pm
FROM {$wpdb->posts} p
LEFT JOIN {$wpdb->postmeta} pm
ON (p.ID = pm.post_id)
WHERE p.post_type = " . CC_MYWC_PLUGIN_SLUG . "'_sa'");
}
/**
* Wipes all posts and related data such as postmeta and related taxonomy of '_ua' post type
* @since 0.1.0
*/
function wipe_user_attributes()
{
global $wpdb;
$wpdb->query("DELETE p,pm
FROM {$wpdb->posts} p
LEFT JOIN {$wpdb->postmeta} pm
ON (p.ID = pm.post_id)
WHERE p.post_type = " . CC_MYWC_PLUGIN_SLUG . "'_ua'");
}
/**
* Delete translation files
* @since 0.1.0
*/
function remove_translation_files()
{
$mo_files = glob(CC_MYWC_PLUGIN_PATH . '/languages/*.mo');
foreach ($mo_files as $mo_file)
unlink(trailingslashit(WP_CONTENT_DIR) . '/languages/plugins/' . wp_basename($mo_file));
}
remove_translation_files();