From 9b7638a7e26401f6e414adf95a385264522fa798 Mon Sep 17 00:00:00 2001 From: magdev Date: Mon, 22 Dec 2025 23:33:12 +0100 Subject: [PATCH] Release version 1.1.19 - Enhanced duplicate detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed persistent duplicate settings page by improving duplicate detection to check by class type and ID instead of strict instance comparison. Issue: - Strict instance comparison (===) failed to detect duplicates - Different object instances of same class not caught by previous check - Settings page still appearing twice despite singleton and instance caching Solution: - Changed duplicate detection from instance comparison to type/ID checks - Added instanceof WC_TPP_Settings check - Added get_id() method check for ID 'tier_package_prices' - Added direct id property check as fallback - Multiple layers of detection to catch duplicates regardless of how created Fixes: - Settings page rendering twice in WooCommerce backend - Duplicate detection failing for different instances of same class Changes: - Enhanced add_settings_page() with multi-layer duplicate detection - Checks: instanceof, get_id(), and id property - Returns early if any existing page matches criteria Technical Details: - Strict comparison only works if exact same object instance - Different instances (even of same class/ID) fail === check - instanceof checks class type regardless of which instance - ID checks ensure no duplicate pages with same identifier - Fallback checks handle different WooCommerce versions/implementations Updated Files: - includes/class-wc-tpp-admin.php (enhanced duplicate detection) - wc-tier-and-package-prices.php (version 1.1.19) - composer.json (version 1.1.19) - CHANGELOG.md (v1.1.19 section) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- CHANGELOG.md | 21 +++++++++++++++++++++ composer.json | 2 +- includes/class-wc-tpp-admin.php | 15 ++++++++++++++- wc-tier-and-package-prices.php | 4 ++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8423e..f21716b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,27 @@ 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.19] - 2025-12-22 + +### Fixed + +- Settings page still appearing twice despite instance caching +- Duplicate detection using strict instance comparison failing for different object instances + +### Changed + +- Enhanced duplicate detection to check by class type and ID instead of instance +- Added `instanceof WC_TPP_Settings` check +- Added ID-based duplicate detection via `get_id()` method and direct property access +- Multiple fallback checks to catch duplicates regardless of instance identity + +### Technical Details + +- Previous strict comparison (`===`) failed when different instances of same class existed +- New approach checks: instanceof, get_id() method, and id property +- Returns early if any settings page with ID 'tier_package_prices' found +- Prevents duplicates even if settings instance recreated or serialized + ## [1.1.18] - 2025-12-22 ### Fixed diff --git a/composer.json b/composer.json index d8c9991..c835adb 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.18", + "version": "1.1.19", "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 cded785..e89794a 100644 --- a/includes/class-wc-tpp-admin.php +++ b/includes/class-wc-tpp-admin.php @@ -35,8 +35,21 @@ if (!class_exists('WC_TPP_Admin')) { } // Check if our settings page is already in the array to prevent duplicates + // Check by class type and ID instead of instance comparison foreach ($settings as $settings_page) { - if ($settings_page === self::$settings_instance) { + if ($settings_page instanceof WC_TPP_Settings) { + return $settings; + } + // Also check by ID property if it's a WC_Settings_Page + if (is_object($settings_page) && + method_exists($settings_page, 'get_id') && + $settings_page->get_id() === 'tier_package_prices') { + return $settings; + } + // Check id property directly + if (is_object($settings_page) && + isset($settings_page->id) && + $settings_page->id === 'tier_package_prices') { return $settings; } } diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index ae7b7ff..69ea88b 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.18 + * Version: 1.1.19 * 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.18'); + define('WC_TPP_VERSION', '1.1.19'); } if (!defined('WC_TPP_PLUGIN_DIR')) { define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));