Only run the uninstaller if the "Uninstall on Delete" option is checked in system status.

This commit is contained in:
Mike Jolley 2015-02-12 11:09:13 +00:00
parent 8aa0e5ea24
commit 2a472e64e8
3 changed files with 32 additions and 29 deletions

View File

@ -53,13 +53,13 @@ if ( ! defined( 'ABSPATH' ) ) {
</td> </td>
</tr> </tr>
<tr> <tr>
<td><?php _e( 'Remove post types on uninstall', 'woocommerce' ); ?></td> <td><?php _e( 'Uninstall on Delete', 'woocommerce' ); ?></td>
<td> <td>
<p> <p>
<label><input type="checkbox" class="checkbox" name="woocommerce_status_options[uninstall_data]" value="1" <?php checked( '1', $options['uninstall_data'] ); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label> <label><input type="checkbox" class="checkbox" name="woocommerce_status_options[uninstall_data]" value="1" <?php checked( '1', $options['uninstall_data'] ); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label>
</p> </p>
<p> <p>
<span class="description"><?php _e( 'This tool will delete all product and order post data when uninstalling via Plugins > Delete.', 'woocommerce' ); ?></span> <span class="description"><?php _e( 'This tool will delete all WooCommerce, Product and Order data when uninstalling via Plugins > Delete.', 'woocommerce' ); ?></span>
</p> </p>
</td> </td>
</tr> </tr>

View File

@ -139,6 +139,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
== Changelog == == Changelog ==
* Fix - Potential notice with preg_match wildcard search, if used incorrectly. * Fix - Potential notice with preg_match wildcard search, if used incorrectly.
* Tweak - Only run the uninstaller if the "Uninstall on Delete" option is checked in system status.
= 2.3.2 - 12/02/2015 = = 2.3.2 - 12/02/2015 =
* Fix - Item meta removal query in order class. * Fix - Item meta removal query in order class.

View File

@ -9,39 +9,41 @@
* @package WooCommerce/Uninstaller * @package WooCommerce/Uninstaller
* @version 2.3.0 * @version 2.3.0
*/ */
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit; exit;
} }
global $wpdb;
$status_options = get_option( 'woocommerce_status_options', array() ); $status_options = get_option( 'woocommerce_status_options', array() );
// Roles + caps
include_once( 'includes/class-wc-install.php' );
WC_Install::remove_roles();
// Pages
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' ) );
// Tables
$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" );
// Delete options
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce_%';");
if ( ! empty( $status_options['uninstall_data'] ) ) { if ( ! empty( $status_options['uninstall_data'] ) ) {
global $wpdb;
// Roles + caps
include_once( 'includes/class-wc-install.php' );
WC_Install::remove_roles();
// Pages
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' ) );
// Tables
$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" );
// Delete options
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce_%';");
// Delete posts + data // Delete posts + data
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" ); $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" );
$wpdb->query( "DELETE FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE wp.ID IS NULL;" ); $wpdb->query( "DELETE FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE wp.ID IS NULL;" );