Prevent notice on settings page when accessing invalid tab

Closes #17367
This commit is contained in:
Mike Jolley 2017-10-25 12:51:19 +01:00
parent f8552ebbad
commit 9d2a493cea
2 changed files with 25 additions and 6 deletions

View File

@ -28,7 +28,13 @@ class WC_Settings_Tax extends WC_Settings_Page {
$this->id = 'tax';
$this->label = __( 'Tax', 'woocommerce' );
parent::__construct();
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
if ( wc_tax_enabled() ) {
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
}
/**

View File

@ -1,23 +1,36 @@
<?php
/**
* Admin View: Settings
*
* @package WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$tab_exists = isset( $tabs[ $current_tab ] ) || has_action( 'woocommerce_sections_' . $current_tab ) || has_action( 'woocommerce_settings_' . $current_tab ) || has_action( 'woocommerce_settings_tabs_' . $current_tab );
$current_tab_label = isset( $tabs[ $current_tab ] ) ? $tabs[ $current_tab ] : '';
if ( ! $tab_exists ) {
wp_safe_redirect( admin_url( 'admin.php?page=wc-settings' ) );
exit;
}
?>
<div class="wrap woocommerce">
<form method="<?php echo esc_attr( apply_filters( 'woocommerce_settings_form_method_tab_' . $current_tab, 'post' ) ); ?>" id="mainform" action="" enctype="multipart/form-data">
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
foreach ( $tabs as $name => $label ) {
echo '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>';
}
do_action( 'woocommerce_settings_tabs' );
foreach ( $tabs as $slug => $label ) {
echo '<a href="' . esc_html( admin_url( 'admin.php?page=wc-settings&tab=' . esc_attr( $slug ) ) ) . '" class="nav-tab ' . ( $current_tab === $slug ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
}
do_action( 'woocommerce_settings_tabs' );
?>
</nav>
<h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1>
<h1 class="screen-reader-text"><?php echo esc_html( $current_tab_label ); ?></h1>
<?php
do_action( 'woocommerce_sections_' . $current_tab );