2011-12-19 15:44:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Uninstall
|
2012-08-14 15:30:23 +00:00
|
|
|
*
|
2015-02-06 15:20:14 +00:00
|
|
|
* Uninstalling WooCommerce deletes user roles, pages, tables, and options.
|
2011-12-19 15:44:00 +00:00
|
|
|
*
|
2017-03-24 16:51:27 +00:00
|
|
|
* @author WooCommerce
|
2015-02-06 15:20:14 +00:00
|
|
|
* @category Core
|
|
|
|
* @package WooCommerce/Uninstaller
|
|
|
|
* @version 2.3.0
|
2011-12-19 15:44:00 +00:00
|
|
|
*/
|
2015-02-12 11:09:13 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
2015-02-06 15:20:14 +00:00
|
|
|
exit;
|
2014-11-25 17:09:19 +00:00
|
|
|
}
|
2011-12-19 15:44:00 +00:00
|
|
|
|
2016-03-17 17:51:13 +00:00
|
|
|
global $wpdb, $wp_version;
|
2013-10-23 16:21:03 +00:00
|
|
|
|
2016-01-25 11:07:01 +00:00
|
|
|
wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' );
|
|
|
|
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
|
|
|
|
wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' );
|
|
|
|
wp_clear_scheduled_hook( 'woocommerce_geoip_updater' );
|
|
|
|
wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );
|
2015-02-12 11:09:13 +00:00
|
|
|
|
2016-08-26 16:00:55 +00:00
|
|
|
/*
|
|
|
|
* Only remove ALL product and page data if WC_REMOVE_ALL_DATA constant is set to true in user's
|
|
|
|
* wp-config.php. This is to prevent data loss when deleting the plugin from the backend
|
|
|
|
* and to ensure only the site owner can perform this action.
|
|
|
|
*/
|
2016-08-24 16:34:13 +00:00
|
|
|
if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
|
2015-10-31 18:55:15 +00:00
|
|
|
// Roles + caps.
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( dirname( __FILE__ ) . '/includes/class-wc-install.php' );
|
2015-02-12 11:09:13 +00:00
|
|
|
WC_Install::remove_roles();
|
|
|
|
|
2015-10-31 18:55:15 +00:00
|
|
|
// Pages.
|
2015-02-12 11:09:13 +00:00
|
|
|
wp_trash_post( get_option( 'woocommerce_shop_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_cart_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_checkout_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_myaccount_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_edit_address_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_view_order_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_change_password_page_id' ) );
|
|
|
|
wp_trash_post( get_option( 'woocommerce_logout_page_id' ) );
|
|
|
|
|
2016-03-23 11:33:47 +00:00
|
|
|
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_attribute_taxonomies';" ) ) {
|
|
|
|
$wc_attributes = array_filter( (array) $wpdb->get_col( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies;" ) );
|
|
|
|
} else {
|
|
|
|
$wc_attributes = array();
|
|
|
|
}
|
2016-03-17 17:51:13 +00:00
|
|
|
|
2015-10-31 18:55:15 +00:00
|
|
|
// Tables.
|
2015-05-15 21:20:49 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_api_keys" );
|
2015-05-15 20:57:18 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_attribute_taxonomies" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_downloadable_product_permissions" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_termmeta" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_tax_rates" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_tax_rate_locations" );
|
2016-01-08 14:53:24 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_shipping_zone_methods" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_shipping_zone_locations" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_shipping_zones" );
|
2016-01-25 11:07:01 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_sessions" );
|
2016-03-01 17:24:32 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_payment_tokens" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_payment_tokenmeta" );
|
2015-02-12 11:09:13 +00:00
|
|
|
|
2015-10-31 18:55:15 +00:00
|
|
|
// Delete options.
|
2016-09-02 01:51:31 +00:00
|
|
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce\_%';" );
|
2015-02-12 11:09:13 +00:00
|
|
|
|
2015-10-31 18:55:15 +00:00
|
|
|
// Delete posts + data.
|
2014-07-11 11:43:42 +00:00
|
|
|
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" );
|
2015-03-27 18:29:01 +00:00
|
|
|
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
|
2015-05-15 20:57:18 +00:00
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_items" );
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_itemmeta" );
|
2016-03-17 17:51:13 +00:00
|
|
|
|
|
|
|
// Delete terms if > WP 4.2 (term splitting was added in 4.2)
|
|
|
|
if ( version_compare( $wp_version, '4.2', '>=' ) ) {
|
|
|
|
// Delete term taxonomies
|
|
|
|
foreach ( array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ) as $taxonomy ) {
|
|
|
|
$wpdb->delete(
|
|
|
|
$wpdb->term_taxonomy,
|
|
|
|
array(
|
|
|
|
'taxonomy' => $taxonomy,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete term attributes
|
|
|
|
foreach ( $wc_attributes as $taxonomy ) {
|
|
|
|
$wpdb->delete(
|
|
|
|
$wpdb->term_taxonomy,
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'pa_' . $taxonomy,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete orphan relationships
|
|
|
|
$wpdb->query( "DELETE tr FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id WHERE posts.ID IS NULL;" );
|
|
|
|
|
|
|
|
// Delete orphan terms
|
|
|
|
$wpdb->query( "DELETE t FROM {$wpdb->terms} t LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
|
|
|
|
|
|
|
|
// Delete orphan term meta
|
|
|
|
if ( ! empty( $wpdb->termmeta ) ) {
|
|
|
|
$wpdb->query( "DELETE tm FROM {$wpdb->termmeta} tm LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 13:23:36 +00:00
|
|
|
|
|
|
|
// Clear any cached data that has been removed
|
|
|
|
wp_cache_flush();
|
2014-08-18 12:45:24 +00:00
|
|
|
}
|