-
Notifications
You must be signed in to change notification settings - Fork 5
/
clean.php
54 lines (43 loc) · 1.52 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
<?php
if ( ! defined( 'WP_CLI' ) ) {
if ( ! current_user_can( 'shop_manager' ) && ! current_user_can( 'administrator' ) ) {
exit( "No permissions\n" );
}
if ( 'GET' === $_SERVER['REQUEST_METHOD'] ) {
?>
<form method="post">
<input type="submit" value="Clean">
</form>
<?php
}
if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
exit;
}
}
global $wpdb;
if ( ! isset( $wpdb->termmeta ) ) {
exit( 'WooCommerce plugin is not active' );
}
wc1c_disable_time_limit();
$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 $wc1c_post_id ) {
$post_attachments = get_attached_media( 'image', $wc1c_post_id );
foreach ( $post_attachments as $post_attachment ) {
wp_delete_attachment( $post_attachment->ID, true );
}
wp_delete_post( $wc1c_post_id, true );
}
echo defined( 'WP_CLI' ) ? "\x07" : 'Done';