woocommerce
Last commit date
assets
4 years ago
i18n
4 years ago
includes
4 years ago
legacy
4 years ago
lib
5 years ago
packages
4 years ago
sample-data
4 years ago
src
4 years ago
templates
4 years ago
vendor
4 years ago
license.txt
6 years ago
readme.txt
4 years ago
uninstall.php
4 years ago
woocommerce.php
4 years ago
uninstall.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Uninstall |
| 4 | * |
| 5 | * Uninstalling WooCommerce deletes user roles, pages, tables, and options. |
| 6 | * |
| 7 | * @package WooCommerce\Uninstaller |
| 8 | * @version 2.3.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'WP_UNINSTALL_PLUGIN' ) || exit; |
| 12 | |
| 13 | global $wpdb, $wp_version; |
| 14 | |
| 15 | wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' ); |
| 16 | wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' ); |
| 17 | wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' ); |
| 18 | wp_clear_scheduled_hook( 'woocommerce_cleanup_personal_data' ); |
| 19 | wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' ); |
| 20 | wp_clear_scheduled_hook( 'woocommerce_geoip_updater' ); |
| 21 | wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); |
| 22 | wp_clear_scheduled_hook( 'woocommerce_cleanup_rate_limits' ); |
| 23 | |
| 24 | /* |
| 25 | * Only remove ALL product and page data if WC_REMOVE_ALL_DATA constant is set to true in user's |
| 26 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
| 27 | * and to ensure only the site owner can perform this action. |
| 28 | */ |
| 29 | if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { |
| 30 | // Drop WC Admin tables. |
| 31 | include_once dirname( __FILE__ ) . '/packages/woocommerce-admin/src/Install.php'; |
| 32 | \Automattic\WooCommerce\Admin\Install::drop_tables(); |
| 33 | |
| 34 | include_once dirname( __FILE__ ) . '/includes/class-wc-install.php'; |
| 35 | |
| 36 | // Roles + caps. |
| 37 | WC_Install::remove_roles(); |
| 38 | |
| 39 | // Pages. |
| 40 | wp_trash_post( get_option( 'woocommerce_shop_page_id' ) ); |
| 41 | wp_trash_post( get_option( 'woocommerce_cart_page_id' ) ); |
| 42 | wp_trash_post( get_option( 'woocommerce_checkout_page_id' ) ); |
| 43 | wp_trash_post( get_option( 'woocommerce_myaccount_page_id' ) ); |
| 44 | wp_trash_post( get_option( 'woocommerce_edit_address_page_id' ) ); |
| 45 | wp_trash_post( get_option( 'woocommerce_view_order_page_id' ) ); |
| 46 | wp_trash_post( get_option( 'woocommerce_change_password_page_id' ) ); |
| 47 | wp_trash_post( get_option( 'woocommerce_logout_page_id' ) ); |
| 48 | |
| 49 | if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}woocommerce_attribute_taxonomies';" ) ) { |
| 50 | $wc_attributes = array_filter( (array) $wpdb->get_col( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies;" ) ); |
| 51 | } else { |
| 52 | $wc_attributes = array(); |
| 53 | } |
| 54 | |
| 55 | // Tables. |
| 56 | WC_Install::drop_tables(); |
| 57 | |
| 58 | // Delete options. |
| 59 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce\_%';" ); |
| 60 | $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'widget\_woocommerce\_%';" ); |
| 61 | |
| 62 | // Delete usermeta. |
| 63 | $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'woocommerce\_%';" ); |
| 64 | |
| 65 | // Delete posts + data. |
| 66 | $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" ); |
| 67 | $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |
| 68 | |
| 69 | $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_type IN ( 'order_note' );" ); |
| 70 | $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" ); |
| 71 | |
| 72 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_items" ); |
| 73 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_itemmeta" ); |
| 74 | |
| 75 | // Delete terms if > WP 4.2 (term splitting was added in 4.2). |
| 76 | if ( version_compare( $wp_version, '4.2', '>=' ) ) { |
| 77 | // Delete term taxonomies. |
| 78 | foreach ( array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ) as $_taxonomy ) { |
| 79 | $wpdb->delete( |
| 80 | $wpdb->term_taxonomy, |
| 81 | array( |
| 82 | 'taxonomy' => $_taxonomy, |
| 83 | ) |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | // Delete term attributes. |
| 88 | foreach ( $wc_attributes as $_taxonomy ) { |
| 89 | $wpdb->delete( |
| 90 | $wpdb->term_taxonomy, |
| 91 | array( |
| 92 | 'taxonomy' => 'pa_' . $_taxonomy, |
| 93 | ) |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | // Delete orphan relationships. |
| 98 | $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;" ); |
| 99 | |
| 100 | // Delete orphan terms. |
| 101 | $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;" ); |
| 102 | |
| 103 | // Delete orphan term meta. |
| 104 | if ( ! empty( $wpdb->termmeta ) ) { |
| 105 | $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;" ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Clear any cached data that has been removed. |
| 110 | wp_cache_flush(); |
| 111 | } |
| 112 |