• Release version 1.1.18 - Fix root cause of duplicate settings

    magdev released this 2025-12-22 22:29:35 +00:00 | 64 commits to main since this release

    Identified and fixed the actual root cause of duplicate settings page:
    automatic instantiation in settings file being executed multiple times.

    Root Cause Analysis:

    • Settings file ended with: return new WC_TPP_Settings();
    • File is in Composer's classmap for autoloading
    • When autoloader loads class, it executes the entire file including instantiation
    • Each include/autoload created a NEW instance despite admin singleton pattern
    • Admin singleton prevented multiple admin instances but not multiple settings instances

    The Fix:

    • Removed automatic instantiation (return new) from settings file
    • Settings file now only contains class definition
    • Admin class explicitly creates instance: new WC_TPP_Settings()
    • Changed from include to require_once to prevent multiple file loads
    • Settings instance now created exactly once, when filter needs it

    Fixes:

    • Settings page rendering twice in WooCommerce backend
    • Multiple WC_TPP_Settings instances being created
    • Composer autoload triggering unintended instantiation

    Changes:

    • Removed line 145 from class-wc-tpp-settings.php (return new WC_TPP_Settings())
    • Modified add_settings_page() to use require_once + explicit new
    • Settings file now side-effect free, safe for autoloading

    Technical Details:

    • Composer classmap autoloader includes files when class is referenced
    • Previous code had side effect (instantiation) on every include
    • New code separates class definition from instantiation
    • Instance creation now controlled explicitly by admin class
    • require_once ensures file loaded once even if accessed multiple times

    Updated Files:

    • includes/class-wc-tpp-settings.php (removed return new line)
    • includes/class-wc-tpp-admin.php (explicit instantiation)
    • wc-tier-and-package-prices.php (version 1.1.18)
    • composer.json (version 1.1.18)
    • CHANGELOG.md (v1.1.18 section)

    🤖 Generated with Claude Code

    Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

    Downloads