Redirect core settings pages when settings feature is enabled (https://github.com/woocommerce/woocommerce-admin/pull/6091)
This commit is contained in:
parent
80f5532543
commit
2780129bad
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue