| @@ -2,18 +2,18 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace TierPricingTable\Settings; |
| 4 | 4 | |
| 5 | 5 | use TierPricingTable\Core\ServiceContainerTrait; |
| 6 | +use TierPricingTable\Settings\CustomOptions\TPTCheckboxListOption; | |
| 6 | 7 | use TierPricingTable\Settings\CustomOptions\TPTDisplayType; |
| 7 | 8 | use TierPricingTable\Settings\CustomOptions\TPTLinkButton; |
| 9 | +use TierPricingTable\Settings\CustomOptions\TPTQuantityMeasurementField; | |
| 8 | 10 | use TierPricingTable\Settings\CustomOptions\TPTTableColumnsField; |
| 9 | -use TierPricingTable\Settings\CustomOptions\TPTQuantityMeasurementField; | |
| 10 | 11 | use TierPricingTable\Settings\CustomOptions\TPTFeatureFlagOption; |
| 11 | 12 | use TierPricingTable\Settings\CustomOptions\TPTIntegrationOption; |
| 12 | 13 | use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 13 | 14 | use TierPricingTable\Settings\CustomOptions\TPTTextTemplate; |
| 14 | 15 | use TierPricingTable\Settings\Sections\Advanced\AdvancedSection; |
| 15 | -use TierPricingTable\Settings\Sections\CalculationLogic\CalculationLogic; | |
| 16 | 16 | use TierPricingTable\Settings\Sections\GeneralSection\GeneralSection; |
| 17 | 17 | use TierPricingTable\Settings\Sections\Integrations\IntegrationSection; |
| 18 | 18 | use TierPricingTable\Settings\Sections\Multicurrency\MulticurrencySection; |
| 19 | 19 | use TierPricingTable\Settings\Sections\ProductAddons\ProductAddonsSection; |
| @@ -87,12 +87,13 @@ | ||
| 87 | 87 | $this->getContainer()->add( 'settings.tpt_switch_option', new TPTSwitchOption() ); |
| 88 | 88 | $this->getContainer()->add( 'settings.tpt_integration_option', new TPTIntegrationOption() ); |
| 89 | 89 | $this->getContainer()->add( 'settings.tpt_feature_flag_option', new TPTFeatureFlagOption() ); |
| 90 | 90 | $this->getContainer()->add( 'settings.tpt_text_template', new TPTTextTemplate() ); |
| 91 | + $this->getContainer()->add( 'settings.tpt_multiple_fields', new TPTTableColumnsField() ); | |
| 91 | 92 | $this->getContainer()->add( 'settings.tpt_display_type', new TPTDisplayType() ); |
| 93 | + $this->getContainer()->add( 'settings.tpt_checkbox_list', new TPTCheckboxListOption() ); | |
| 92 | 94 | $this->getContainer()->add( 'settings.tpt_link_button', new TPTLinkButton() ); |
| 93 | 95 | $this->getContainer()->add( 'settings.tpt_quantity_measurement', new TPTQuantityMeasurementField() ); |
| 94 | - $this->getContainer()->add( 'settings.tpt_multiple_fields', new TPTTableColumnsField() ); | |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | protected function initSections() { |
| 98 | 99 | } |
| @@ -118,17 +119,15 @@ | ||
| 118 | 119 | */ |
| 119 | 120 | protected function sortSections( array $sections ) : array { |
| 120 | 121 | $order = (array) apply_filters( 'tiered_pricing_table/settings/sections_order', array( |
| 121 | 122 | 'general' => 10, |
| 122 | - 'calculation_logic' => 20, | |
| 123 | 123 | 'shop-loop-display' => 30, |
| 124 | 124 | 'tier-labels' => 40, |
| 125 | 125 | 'request-a-quote' => 50, |
| 126 | - 'advanced' => 60, | |
| 127 | 126 | 'integrations' => 70, |
| 128 | 127 | 'multicurrency' => 80, |
| 129 | 128 | 'product-addons' => 90, |
| 130 | - 'tools' => 110, | |
| 129 | + 'advanced' => 120, | |
| 131 | 130 | ) ); |
| 132 | 131 | // Stable sort: usort() is only guaranteed stable on PHP 8+, so tie-break on the original index. |
| 133 | 132 | $indexed = array(); |
| 134 | 133 | foreach ( array_values( $sections ) as $index => $section ) { |
| @@ -145,9 +144,8 @@ | ||
| 145 | 144 | */ |
| 146 | 145 | public function initSettings() { |
| 147 | 146 | $this->sections = apply_filters( 'tiered_pricing_table/settings/sections', array( |
| 148 | 147 | new GeneralSection(), |
| 149 | - new CalculationLogic(), | |
| 150 | 148 | new AdvancedSection(), |
| 151 | 149 | new MulticurrencySection(), |
| 152 | 150 | new ProductAddonsSection(), |
| 153 | 151 | new IntegrationSection() |
| @@ -152,8 +150,29 @@ | ||
| 152 | 150 | new ProductAddonsSection(), |
| 153 | 151 | new IntegrationSection() |
| 154 | 152 | ) ); |
| 155 | 153 | $this->sections = $this->sortSections( $this->sections ); |
| 154 | + // Only on the plugin's own settings tab: other WooCommerce tabs (REST API keys, webhooks, tax, | |
| 155 | + // shipping…) use the same "section" parameter and must never see it rewritten. | |
| 156 | + if ( $this->isOwnSettingsTab() ) { | |
| 157 | + // The "Tools" tab merged into "Advanced" in 7.2.1; old links and bookmarks keep working. | |
| 158 | + if ( isset( $_GET['section'] ) && 'tools' === $_GET['section'] ) { | |
| 159 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 160 | + $_GET['section'] = 'advanced'; | |
| 161 | + } | |
| 162 | + // A removed or unknown section in the URL (old links to the "Calculations" tab, for example) | |
| 163 | + // opens the default section instead of an empty page. The sections read the request directly. | |
| 164 | + if ( isset( $_GET['section'] ) ) { | |
| 165 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 166 | + $known = array_map( function ( $section ) { | |
| 167 | + return $section->getSlug(); | |
| 168 | + }, $this->sections ); | |
| 169 | + if ( !in_array( sanitize_text_field( wp_unslash( $_GET['section'] ) ), $known, true ) ) { | |
| 170 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 171 | + unset($_GET['section']); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + } | |
| 156 | 175 | foreach ( $this->sections as $section ) { |
| 157 | 176 | if ( $section->isActive() ) { |
| 158 | 177 | $this->settings = $section->getSettings(); |
| 159 | 178 | break; |
| @@ -169,8 +188,16 @@ | ||
| 169 | 188 | add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, array($this, 'addTieredPricingTableSettings') ); |
| 170 | 189 | add_filter( 'woocommerce_settings_tabs_array', array($this, 'addSettingsTab'), 50 ); |
| 171 | 190 | add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, array($this, 'updateSettings') ); |
| 172 | 191 | add_action( 'woocommerce_settings_' . self::SETTINGS_PAGE, array($this, 'renderSections'), 99 ); |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Whether the request is for the plugin's own WooCommerce settings tab. | |
| 196 | + */ | |
| 197 | + protected function isOwnSettingsTab() : bool { | |
| 198 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 199 | + return is_admin() && isset( $_GET['page'], $_GET['tab'] ) && 'wc-settings' === $_GET['page'] && self::SETTINGS_PAGE === $_GET['tab']; | |
| 173 | 200 | } |
| 174 | 201 | |
| 175 | 202 | public function renderSections() { |
| 176 | 203 | // Opening a section clears its "unread" indicator (store-wide) |