From 2dc3e5252f7ddc1a9fa893df2893a1fd7f4111c6 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 24 Aug 2016 16:46:07 +0100 Subject: [PATCH 1/4] Made WC_TEMPLATE_DEBUG_MODE a constant only --- includes/wc-core-functions.php | 15 --------------- woocommerce.php | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index bf47cd324d0..848ccdf60c1 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -893,21 +893,6 @@ function wc_deliver_webhook_async( $webhook_id, $arg ) { } add_action( 'woocommerce_deliver_webhook_async', 'wc_deliver_webhook_async', 10, 2 ); -/** - * Enables template debug mode. - */ -function wc_template_debug_mode() { - if ( ! defined( 'WC_TEMPLATE_DEBUG_MODE' ) ) { - $status_options = get_option( 'woocommerce_status_options', array() ); - if ( ! empty( $status_options['template_debug_mode'] ) && current_user_can( 'manage_options' ) ) { - define( 'WC_TEMPLATE_DEBUG_MODE', true ); - } else { - define( 'WC_TEMPLATE_DEBUG_MODE', false ); - } - } -} -add_action( 'after_setup_theme', 'wc_template_debug_mode', 20 ); - /** * Formats a string in the format COUNTRY:STATE into an array. * diff --git a/woocommerce.php b/woocommerce.php index 25eadd8b6ce..9950a8bed6b 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -188,6 +188,7 @@ final class WooCommerce { $this->define( 'WC_DELIMITER', '|' ); $this->define( 'WC_LOG_DIR', $upload_dir['basedir'] . '/wc-logs/' ); $this->define( 'WC_SESSION_CACHE_GROUP', 'wc_session_id' ); + $this->define( 'WC_TEMPLATE_DEBUG_MODE', false ); } /** From 84487d0f4b01eeb6ea3b227e8ae3c2f18378acd2 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 24 Aug 2016 16:55:34 +0100 Subject: [PATCH 2/4] Shipping debug mode moved to shipping settings --- includes/admin/settings/class-wc-settings-shipping.php | 10 ++++++++++ includes/class-wc-shipping.php | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/admin/settings/class-wc-settings-shipping.php b/includes/admin/settings/class-wc-settings-shipping.php index c6a35502417..044f1a7f823 100644 --- a/includes/admin/settings/class-wc-settings-shipping.php +++ b/includes/admin/settings/class-wc-settings-shipping.php @@ -111,6 +111,16 @@ class WC_Settings_Shipping extends WC_Settings_Page { 'show_if_checked' => 'option', ), + array( + 'title' => __( 'Debug Mode', 'woocommerce' ), + 'desc' => __( 'Enable Debug Mode', 'woocommerce' ), + 'desc_tip' => __( 'Enable Shipping Debug Mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ), + 'id' => 'woocommerce_shipping_debug_mode', + 'default' => 'no', + 'type' => 'checkbox', + 'autoload' => false + ), + array( 'type' => 'sectionend', 'id' => 'shipping_options' ), ) ); diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index ea7ddb07f08..5f212f9b14f 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -132,12 +132,12 @@ class WC_Shipping { */ public function load_shipping_methods( $package = array() ) { if ( ! empty( $package ) ) { - $status_options = get_option( 'woocommerce_status_options', array() ); + $debug_mode = 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ); $shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $package ); $this->shipping_methods = $shipping_zone->get_shipping_methods( true ); // Debug output - if ( ! empty( $status_options['shipping_debug_mode'] ) && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! wc_has_notice( 'Customer matched zone "' . $shipping_zone->get_zone_name() . '"' ) ) { + if ( $debug_mode && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! wc_has_notice( 'Customer matched zone "' . $shipping_zone->get_zone_name() . '"' ) ) { wc_add_notice( 'Customer matched zone "' . $shipping_zone->get_zone_name() . '"' ); } } else { @@ -353,7 +353,7 @@ class WC_Shipping { $session_key = 'shipping_for_package_' . $package_key; $stored_rates = WC()->session->get( $session_key ); - if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || ! empty( $status_options['shipping_debug_mode'] ) ) { + if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) ) { // Calculate shipping method rates $package['rates'] = array(); From 49283e5576f1dd8539e5db3be4bfd7fb560ab1de Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 24 Aug 2016 17:34:13 +0100 Subject: [PATCH 3/4] uninstall_data replaced with constant. --- tests/bootstrap.php | 2 +- tests/unit-tests/util/install.php | 4 ++-- uninstall.php | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d0dede09717..fe531a3c5cf 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -71,7 +71,7 @@ class WC_Unit_Tests_Bootstrap { // clean existing install first define( 'WP_UNINSTALL_PLUGIN', true ); - update_option( 'woocommerce_status_options', array( 'uninstall_data' => 1 ) ); + define( 'WC_REMOVE_ALL_DATA', true ); include( $this->plugin_dir . '/uninstall.php' ); WC_Install::install(); diff --git a/tests/unit-tests/util/install.php b/tests/unit-tests/util/install.php index 84a26045dc6..116ba22c10f 100644 --- a/tests/unit-tests/util/install.php +++ b/tests/unit-tests/util/install.php @@ -32,7 +32,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { // clean existing install first if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { define( 'WP_UNINSTALL_PLUGIN', true ); - update_option( 'woocommerce_status_options', array( 'uninstall_data' => 1 ) ); + define( 'WC_REMOVE_ALL_DATA', true ); } include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); @@ -86,7 +86,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case { // Clean existing install first if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { define( 'WP_UNINSTALL_PLUGIN', true ); - update_option( 'woocommerce_status_options', array( 'uninstall_data' => 1 ) ); + define( 'WC_REMOVE_ALL_DATA', true ); } include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' ); diff --git a/uninstall.php b/uninstall.php index f6ffed61dff..2affcd50a91 100644 --- a/uninstall.php +++ b/uninstall.php @@ -24,7 +24,10 @@ wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); $status_options = get_option( 'woocommerce_status_options', array() ); -if ( ! empty( $status_options['uninstall_data'] ) ) { +// 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. +if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { // Roles + caps. include_once( dirname( __FILE__ ) . '/includes/class-wc-install.php' ); WC_Install::remove_roles(); From 0667c1cde13d79faae51244bb8a7aa81632c2f5a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 24 Aug 2016 17:35:13 +0100 Subject: [PATCH 4/4] Remove option based tools --- includes/admin/class-wc-admin-menus.php | 1 - .../views/html-admin-page-status-tools.php | 34 ------------------- includes/class-wc-shipping.php | 7 ++-- uninstall.php | 2 -- 4 files changed, 3 insertions(+), 41 deletions(-) diff --git a/includes/admin/class-wc-admin-menus.php b/includes/admin/class-wc-admin-menus.php index 18e199dc217..1d6a4367484 100644 --- a/includes/admin/class-wc-admin-menus.php +++ b/includes/admin/class-wc-admin-menus.php @@ -95,7 +95,6 @@ class WC_Admin_Menus { */ public function status_menu() { add_submenu_page( 'woocommerce', __( 'WooCommerce Status', 'woocommerce' ), __( 'System Status', 'woocommerce' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) ); - register_setting( 'woocommerce_status_settings_fields', 'woocommerce_status_options' ); } /** diff --git a/includes/admin/views/html-admin-page-status-tools.php b/includes/admin/views/html-admin-page-status-tools.php index 9a935a7fed3..8126b35d299 100644 --- a/includes/admin/views/html-admin-page-status-tools.php +++ b/includes/admin/views/html-admin-page-status-tools.php @@ -10,7 +10,6 @@ if ( ! defined( 'ABSPATH' ) ) { ?>
- 0, 'template_debug_mode' => 0, 'shipping_debug_mode' => 0 ) ); ?> $tool ) : ?> @@ -24,39 +23,6 @@ if ( ! defined( 'ABSPATH' ) ) { - - - - - - - - - - - -
-

- -

-

- -

-
-

- -

-

- -

-
-

- -

-

- -

-

diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 5f212f9b14f..758f62bed50 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -348,10 +348,9 @@ class WC_Shipping { unset( $package_to_hash['contents'][ $item_id ]['data'] ); } - $package_hash = 'wc_ship_' . md5( json_encode( $package_to_hash ) . WC_Cache_Helper::get_transient_version( 'shipping' ) ); - $status_options = get_option( 'woocommerce_status_options', array() ); - $session_key = 'shipping_for_package_' . $package_key; - $stored_rates = WC()->session->get( $session_key ); + $package_hash = 'wc_ship_' . md5( json_encode( $package_to_hash ) . WC_Cache_Helper::get_transient_version( 'shipping' ) ); + $session_key = 'shipping_for_package_' . $package_key; + $stored_rates = WC()->session->get( $session_key ); if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) ) { // Calculate shipping method rates diff --git a/uninstall.php b/uninstall.php index 2affcd50a91..48d826d379e 100644 --- a/uninstall.php +++ b/uninstall.php @@ -22,8 +22,6 @@ wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' ); wp_clear_scheduled_hook( 'woocommerce_geoip_updater' ); wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' ); -$status_options = get_option( 'woocommerce_status_options', array() ); - // 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.