From 2780129bad4d7ddf35677b77136755e89ad49389 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Fri, 12 Feb 2021 16:58:26 -0500 Subject: [PATCH] Redirect core settings pages when settings feature is enabled (https://github.com/woocommerce/woocommerce-admin/pull/6091) --- .../src/Features/Settings.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/woocommerce-admin/src/Features/Settings.php b/plugins/woocommerce-admin/src/Features/Settings.php index 87c75c69cff..7c14356df75 100644 --- a/plugins/woocommerce-admin/src/Features/Settings.php +++ b/plugins/woocommerce-admin/src/Features/Settings.php @@ -53,6 +53,7 @@ class Settings { add_filter( 'woocommerce_shared_settings', array( __CLASS__, 'add_component_settings' ) ); // Run this after the original WooCommerce settings have been added. add_action( 'admin_menu', array( $this, 'register_pages' ), 60 ); + add_action( 'init', array( $this, 'redirect_core_settings_pages' ) ); } /** @@ -153,4 +154,26 @@ class Settings { } } } + + /** + * Redirect the old settings page URLs to the new ones. + */ + public function redirect_core_settings_pages() { + /* phpcs:disable WordPress.Security.NonceVerification */ + if ( ! isset( $_GET['page'] ) || 'wc-settings' !== $_GET['page'] ) { + return; + } + + if ( ! current_user_can( 'manage_woocommerce' ) ) { + return; + } + + $setting_pages = \WC_Admin_Settings::get_settings_pages(); + $default_setting = isset( $setting_pages[0] ) ? $setting_pages[0]->get_id() : ''; + $setting = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : $default_setting; + /* phpcs:enable */ + + wp_safe_redirect( wc_admin_url( "&path=/settings/$setting" ) ); + exit; + } }