From 43af20755828ab18591c8f01af1c0fa0e56ba3f9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 28 Apr 2016 12:36:49 +0100 Subject: [PATCH] Output buffering and redirects after turning off legacy Closes #10806 --- includes/admin/class-wc-admin.php | 8 ++++++++ .../admin/settings/class-wc-settings-shipping.php | 2 +- .../class-wc-shipping-legacy-flat-rate.php | 12 ++++++++++++ .../class-wc-shipping-legacy-free-shipping.php | 12 ++++++++++++ .../class-wc-shipping-legacy-local-delivery.php | 12 ++++++++++++ .../class-wc-shipping-legacy-local-pickup.php | 12 ++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index b0dd89e9840..f699bbd3649 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -24,6 +24,7 @@ class WC_Admin { public function __construct() { add_action( 'init', array( $this, 'includes' ) ); add_action( 'current_screen', array( $this, 'conditional_includes' ) ); + add_action( 'admin_init', array( $this, 'buffer' ), 1 ); add_action( 'admin_init', array( $this, 'preview_emails' ) ); add_action( 'admin_init', array( $this, 'prevent_admin_access' ) ); add_action( 'admin_init', array( $this, 'admin_redirects' ) ); @@ -31,6 +32,13 @@ class WC_Admin { add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 ); } + /** + * Output buffering allows admin screens to make redirects later on. + */ + public function buffer() { + ob_start(); + } + /** * Include any classes we need within admin. */ diff --git a/includes/admin/settings/class-wc-settings-shipping.php b/includes/admin/settings/class-wc-settings-shipping.php index 03625b391ca..722240db95b 100644 --- a/includes/admin/settings/class-wc-settings-shipping.php +++ b/includes/admin/settings/class-wc-settings-shipping.php @@ -127,7 +127,7 @@ class WC_Settings_Shipping extends WC_Settings_Page { // Load shipping methods so we can show any global options they may have $shipping_methods = WC()->shipping->load_shipping_methods(); - if ( '' == $current_section ) { + if ( '' === $current_section ) { $this->output_zones_screen(); } elseif ( 'options' === $current_section ) { $settings = $this->get_settings(); diff --git a/includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php b/includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php index bc68df244ea..a8f879587f2 100644 --- a/includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php +++ b/includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php @@ -31,6 +31,18 @@ class WC_Shipping_Legacy_Flat_Rate extends WC_Shipping_Method { add_action( 'woocommerce_flat_rate_shipping_add_rate', array( $this, 'calculate_extra_shipping' ), 10, 2 ); } + /** + * Process and redirect if disabled. + */ + public function process_admin_options() { + parent::process_admin_options(); + + if ( 'no' === $this->settings[ 'enabled' ] ) { + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) ); + exit; + } + } + /** * Return the name of the option in the WP DB. * @since 2.6.0 diff --git a/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php b/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php index baf131958e4..203c76a61ae 100644 --- a/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php +++ b/includes/shipping/legacy-free-shipping/class-wc-shipping-legacy-free-shipping.php @@ -32,6 +32,18 @@ class WC_Shipping_Legacy_Free_Shipping extends WC_Shipping_Method { $this->init(); } + /** + * Process and redirect if disabled. + */ + public function process_admin_options() { + parent::process_admin_options(); + + if ( 'no' === $this->settings[ 'enabled' ] ) { + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) ); + exit; + } + } + /** * Return the name of the option in the WP DB. * @since 2.6.0 diff --git a/includes/shipping/legacy-local-delivery/class-wc-shipping-legacy-local-delivery.php b/includes/shipping/legacy-local-delivery/class-wc-shipping-legacy-local-delivery.php index 97f83312dfd..f590e7b2135 100644 --- a/includes/shipping/legacy-local-delivery/class-wc-shipping-legacy-local-delivery.php +++ b/includes/shipping/legacy-local-delivery/class-wc-shipping-legacy-local-delivery.php @@ -26,6 +26,18 @@ class WC_Shipping_Legacy_Local_Delivery extends WC_Shipping_Local_Pickup { $this->init(); } + /** + * Process and redirect if disabled. + */ + public function process_admin_options() { + parent::process_admin_options(); + + if ( 'no' === $this->settings[ 'enabled' ] ) { + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) ); + exit; + } + } + /** * Return the name of the option in the WP DB. * @since 2.6.0 diff --git a/includes/shipping/legacy-local-pickup/class-wc-shipping-legacy-local-pickup.php b/includes/shipping/legacy-local-pickup/class-wc-shipping-legacy-local-pickup.php index bf52e161b48..afe834aeb70 100644 --- a/includes/shipping/legacy-local-pickup/class-wc-shipping-legacy-local-pickup.php +++ b/includes/shipping/legacy-local-pickup/class-wc-shipping-legacy-local-pickup.php @@ -26,6 +26,18 @@ class WC_Shipping_Legacy_Local_Pickup extends WC_Shipping_Method { $this->init(); } + /** + * Process and redirect if disabled. + */ + public function process_admin_options() { + parent::process_admin_options(); + + if ( 'no' === $this->settings[ 'enabled' ] ) { + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=options' ) ); + exit; + } + } + /** * Return the name of the option in the WP DB. * @since 2.6.0