forked from sgtpep/woocommerce-1c
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean.php
63 lines (51 loc) · 2.02 KB
/
clean.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
<?php
if (!defined('WP_CLI')) {
if (!current_user_can('shop_manager') && !current_user_can('administrator')) exit("No permissions\n");
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
?>
<form method="post">
<input type="submit" value="Clean">
</form>
<?php
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') exit;
}
global $wpdb;
if (!isset($wpdb->termmeta)) exit("WooCommerce plugin is not active");
wc1c_disable_time_limit();
// if (is_dir(WC1C_DATA_DIR)) {
// $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(WC1C_DATA_DIR, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
// foreach ($iterator as $path => $item) {
// if ($item->isDir()) {
// rmdir($path) or wc1c_error(sprintf("Failed to remove directory %s", $path));
// }
// else {
// unlink($path) or wc1c_error(sprintf("Failed to unlink file %s", $path));
// }
// }
// }
// else {
// mkdir(WC1C_DATA_DIR) or wc1c_error(sprintf("Failed to make directory %s", WC1C_DATA_DIR));
// }
$rows = $wpdb->get_results("SELECT tm.term_id, taxonomy FROM $wpdb->termmeta tm JOIN $wpdb->term_taxonomy tt ON tm.term_id = tt.term_id WHERE meta_key = 'wc1c_guid'");
foreach ($rows as $row) {
wp_delete_term($row->term_id, $row->taxonomy);
}
$attribute_ids = get_option('wc1c_guid_attributes', array());
foreach ($attribute_ids as $attribute_id) {
wc1c_delete_woocommerce_attribute($attribute_id);
}
delete_transient('wc_attribute_taxonomies');
$option_names = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'wc1c_%'");
foreach ($option_names as $option_name) {
delete_option($option_name);
}
$post_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wc1c_guid'");
foreach ($post_ids as $post_id) {
$post_attachments = get_attached_media('image', $post_id);
foreach ($post_attachments as $post_attachment) {
wp_delete_attachment($post_attachment->ID, true);
}
wp_delete_post($post_id, true);
}
echo defined('WP_CLI') ? "\x07" : "Done";