Redirect core settings pages when settings feature is enabled (https://github.com/woocommerce/woocommerce-admin/pull/6091)

This commit is contained in:
Joshua T Flowers 2021-02-12 16:58:26 -05:00 committed by GitHub
parent 80f5532543
commit 2780129bad
1 changed files with 23 additions and 0 deletions

View File

@ -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;
}
}