From e46372da51d81bab7feb31e637949c0a241dfdcb Mon Sep 17 00:00:00 2001 From: magdev Date: Mon, 22 Dec 2025 23:05:11 +0100 Subject: [PATCH] Release version 1.1.17 - Array duplicate prevention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed persistent duplicate settings page by adding array-level duplicate detection in addition to singleton pattern from v1.1.16. Root Cause: - WooCommerce calls woocommerce_get_settings_pages filter multiple times - Even with singleton pattern, each filter call added settings instance to array - Singleton prevented multiple class instances but not multiple array entries Fixes: - Settings page rendering twice despite singleton pattern in v1.1.16 - Filter adding same settings instance to array on repeated calls Changes: - Added duplicate detection loop in add_settings_page() before array append - Uses strict comparison (===) to check if instance already in array - Returns early if settings page already present, preventing duplicate Technical Details: - foreach loop iterates through existing $settings array - Compares each element against cached self::$settings_instance - Only appends to array if instance not found - Complements singleton pattern with array-level protection - Handles WooCommerce calling filter multiple times during page load Updated Files: - includes/class-wc-tpp-admin.php (added duplicate check in filter) - wc-tier-and-package-prices.php (version 1.1.17) - composer.json (version 1.1.17) - CHANGELOG.md (v1.1.17 section) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- CHANGELOG.md | 20 ++++++++++++++++++++ composer.json | 2 +- includes/class-wc-tpp-admin.php | 8 ++++++++ wc-tier-and-package-prices.php | 4 ++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3deca9c..ef6a28c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,26 @@ All notable changes to WooCommerce Tier and Package Prices will be documented in The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.17] - 2025-12-22 + +### Fixed + +- Settings page still rendering twice despite singleton pattern in v1.1.16 +- Filter adding settings instance to array multiple times when called repeatedly + +### Changed + +- Added duplicate detection in `add_settings_page()` filter method +- Filter now checks if settings instance already exists in array before adding + +### Technical Details + +- Added foreach loop to check existing settings pages in array +- Uses strict comparison (`===`) to detect if exact instance already present +- Returns early if settings instance found, preventing duplicate array entries +- Complements singleton pattern from v1.1.16 with array-level duplicate prevention +- Handles edge case where WooCommerce calls filter multiple times + ## [1.1.16] - 2025-12-22 ### Fixed diff --git a/composer.json b/composer.json index cb3e94d..cefa5e6 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "magdev/wc-tier-package-prices", "description": "WooCommerce plugin for tier pricing and package prices with Twig templates", - "version": "1.1.16", + "version": "1.1.17", "type": "wordpress-plugin", "license": "GPL-2.0-or-later", "authors": [ diff --git a/includes/class-wc-tpp-admin.php b/includes/class-wc-tpp-admin.php index 3bde1d0..96b9241 100644 --- a/includes/class-wc-tpp-admin.php +++ b/includes/class-wc-tpp-admin.php @@ -32,6 +32,14 @@ if (!class_exists('WC_TPP_Admin')) { if (null === self::$settings_instance) { self::$settings_instance = include WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-settings.php'; } + + // Check if our settings page is already in the array to prevent duplicates + foreach ($settings as $settings_page) { + if ($settings_page === self::$settings_instance) { + return $settings; + } + } + $settings[] = self::$settings_instance; return $settings; } diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index 505b7c3..7c808a0 100644 --- a/wc-tier-and-package-prices.php +++ b/wc-tier-and-package-prices.php @@ -4,7 +4,7 @@ * Plugin Name: WooCommerce Tier and Package Prices * Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-tier-package-prices * Description: Add tier pricing and package prices to WooCommerce products with configurable quantities at fixed prices - * Version: 1.1.16 + * Version: 1.1.17 * Author: Marco Graetsch * Author URI: https://src.bundespruefstelle.ch/magdev * Text Domain: wc-tier-package-prices @@ -23,7 +23,7 @@ if (!defined('ABSPATH')) { // Define plugin constants if (!defined('WC_TPP_VERSION')) { - define('WC_TPP_VERSION', '1.1.16'); + define('WC_TPP_VERSION', '1.1.17'); } if (!defined('WC_TPP_PLUGIN_DIR')) { define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));