Uninstall option Closes #3968. Change option for #3992

This commit is contained in:
Mike Jolley 2013-10-23 17:21:03 +01:00
parent 56714e1d62
commit 90ba359ef9
3 changed files with 50 additions and 27 deletions

View File

@ -1,6 +1,6 @@
<form method="post" action="options.php">
<?php settings_fields( 'woocommerce_status_settings_fields' ); ?>
<?php $options = get_option( 'woocommerce_status_options' ); ?>
<?php $options = wp_parse_args( get_option( 'woocommerce_status_options', array() ), array( 'uninstall_data' => 0, 'template_debug_mode' => 0 ) ); ?>
<table class="wc_status_table widefat" cellspacing="0">
<thead class="tools">
<tr>
@ -8,28 +8,39 @@
</tr>
</thead>
<tbody class="tools">
<?php foreach( $tools as $action => $tool ) { ?>
<tr>
<td><?php echo esc_html( $tool['name'] ); ?></td>
<td>
<p>
<a href="<?php echo wp_nonce_url( admin_url('admin.php?page=wc_status&tab=tools&action=' . $action ), 'debug_action' ); ?>" class="button"><?php echo esc_html( $tool['button'] ); ?></a>
<span class="description"><?php echo wp_kses_post( $tool['desc'] ); ?></span>
<?php foreach( $tools as $action => $tool ) { ?>
<tr>
<td><?php echo esc_html( $tool['name'] ); ?></td>
<td>
<p>
<a href="<?php echo wp_nonce_url( admin_url('admin.php?page=wc_status&tab=tools&action=' . $action ), 'debug_action' ); ?>" class="button"><?php echo esc_html( $tool['button'] ); ?></a>
<span class="description"><?php echo wp_kses_post( $tool['desc'] ); ?></span>
</p>
</td>
</tr>
<?php } ?>
<tr>
<td><?php _e( 'Template Debug Mode', 'woocommerce' ); ?></td>
<td>
<p>
<label><input type="checkbox" class="checkbox" name="woocommerce_status_options[template_debug_mode]" value="1" <?php checked( '1', $options['template_debug_mode'] ); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label>
</p>
</td>
</tr>
<?php } ?>
<tr>
<td><?php _e( 'Template Debug Mode', 'woocommerce' ); ?></td>
<td>
<p>
<label><input type="checkbox" class="checkbox" name="woocommerce_status_options" value="1" <?php checked('1', $options); ?> /> <?php _e( 'Enabled', 'woocommerce' ); ?></label>
</p>
<p>
<span class="description"><?php _e( 'This tool will disable template overrides for logged-in administrators for debugging purposes.', 'woocommerce' ); ?></span>
</p>
</td>
</tr>
<p>
<span class="description"><?php _e( 'This tool will disable template overrides for logged-in administrators for debugging purposes.', 'woocommerce' ); ?></span>
</p>
</td>
</tr>
<tr>
<td><?php _e( 'Remove post types on uninstall', 'woocommerce' ); ?></td>
<td>
<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>
</p>
<p>
<span class="description"><?php _e( 'This tool will delete all product and order post data when uninstalling via Plugins > Delete.', 'woocommerce' ); ?></span>
</p>
</td>
</tr>
</tbody>
</table>
<p class="submit">

View File

@ -62,8 +62,9 @@ class WC_Template_Loader {
}
if ( $file ) {
$template = locate_template( $find );
if ( ! $template || ( get_option( 'woocommerce_status_options' ) && current_user_can( 'manage_options' ) ) )
$template = locate_template( $find );
$status_options = get_option( 'woocommerce_status_options', array() );
if ( ! $template || ( ! empty( $status_options['template_debug_mode'] ) && current_user_can( 'manage_options' ) ) )
$template = WC()->plugin_path() . '/templates/' . $file;
}

View File

@ -7,12 +7,15 @@
* @author WooThemes
* @category Core
* @package WooCommerce/Uninstaller
* @version 1.6.4
* @version 2.1.0
*/
if( !defined('WP_UNINSTALL_PLUGIN') ) exit();
if( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
exit();
global $wpdb, $wp_roles;
$status_options = get_option( 'woocommerce_status_options', array() );
// Roles + caps
$installer = include( 'includes/class-wc-install.php' );
$installer->remove_roles();
@ -41,4 +44,12 @@ $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_%';");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce_%';");
if ( ! empty( $status_options['uninstall_data'] ) ) {
// Delete posts + data
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order' );" );
$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( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_order_items" );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_order_itemmeta" );
}