// } // 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') ? "" : "Done";
function wc1c_clean_woocommerce_attributes($is_full) { global $wpdb; if (!$is_full || WC1C_PREVENT_CLEAN) { return; } $timestamps = get_option('wc1c_timestamp_attributes', array()); if (!$timestamps) { return; } $guids = get_option('wc1c_guid_attributes', array()); $attribute_ids = array(); foreach ($timestamps as $guid => $timestamp) { if ($timestamp != WC1C_TIMESTAMP) { $attribute_ids[] = $guids[$guid]; } } $attribute_ids = apply_filters('wc1c_clean_attributes', $attribute_ids); if (!$attribute_ids) { return; } foreach ($attribute_ids as $attribute_id) { $attribute = wc1c_woocommerce_attribute_by_id($attribute_id); if (!$attribute) { continue; } wc1c_delete_woocommerce_attribute($attribute_id); unset($guids[$guid]); unset($timestamps[$guid]); $is_deleted = true; } if (!empty($is_deleted)) { $orders = get_option('wc1c_order_attributes', array()); $order_index = array_search($attribute_id, $orders); if ($order_index !== false) { unset($orders[$order_index]); update_option('wc1c_order_attributes', $orders); } update_option('wc1c_guid_attributes', $guids); update_option('wc1c_timestamp_attributes', $timestamps); } }