MaxtDesign

Developer Guide

Plugin Architecture

Class Structure

  • MaxtDesign_Role_Based_Pricing — Main plugin class. Singleton. Handles pricing hooks, price display, and in-memory original price storage.
  • MaxtDesign_RBP_Core — Core engine. Database operations, pricing calculations, role management, and caching system.
  • MaxtDesign_RBP_Admin — Admin interface. Settings pages, meta boxes, AJAX handlers.
  • MaxtDesign_RBP_Frontend — Frontend styles. Only enqueues CSS on WooCommerce pages.
  • Constants

    MAXTDESIGN_RBP_VERSION           // '1.1.0'
    MAXTDESIGN_RBP_PLUGIN_FILE       // Main plugin file path
    MAXTDESIGN_RBP_PLUGIN_DIR        // Plugin directory path
    MAXTDESIGN_RBP_PLUGIN_URL        // Plugin URL for assets
    MAXTDESIGN_RBP_PLUGIN_BASENAME   // Plugin basename for hooks
    MAXTDESIGN_RBP_PERFORMANCE_MONITORING  // false by default (developer tool)

    Database Schema

    Product Rules Table (`wp_maxtdesign_rbp_rules`)

    id           mediumint(9)   AUTO_INCREMENT PRIMARY KEY
    role_name    varchar(100)   NOT NULL
    product_id   bigint(20)     DEFAULT NULL
    discount_type varchar(20)   DEFAULT 'percentage'
    discount_value decimal(10,2) DEFAULT 0.00
    created_at   datetime       DEFAULT CURRENT_TIMESTAMP

    Indexes: idx_role_name, idx_product_id, idx_role_product (compound), idx_created_at

    Global Rules Table (`wp_maxtdesign_rbp_global_rules`)

    id           mediumint(9)   AUTO_INCREMENT PRIMARY KEY
    role_name    varchar(100)   NOT NULL (UNIQUE)
    discount_type varchar(20)   DEFAULT 'percentage'
    discount_value decimal(10,2) DEFAULT 0.00
    is_active    tinyint(1)     DEFAULT 1
    created_at   datetime       DEFAULT CURRENT_TIMESTAMP
    updated_at   datetime       ON UPDATE CURRENT_TIMESTAMP

    Indexes: idx_role_name (unique), idx_is_active, idx_role_active (compound)

    Caching Internals

    Cache Key Format

    maxtdesign_rbp_price_{product_id}_{role_name}

    Cache Method Detection

    The plugin auto-detects the best available cache:

    // Priority order:
    1. Object cache (Redis/Memcached) — 3600s TTL
    2. WordPress transients — 1800s TTL

    In-Memory Storage

    Original prices are stored in a static array during the request lifecycle:

    // MaxtDesign_Role_Based_Pricing::$original_prices
    // Keyed by product_id, stores original price before modification
    // Eliminates DB meta writes for original price tracking

    A static flag $user_has_discounts enables early returns in display methods when the current user has no applicable rules.

    Performance Monitoring

    Enable detailed performance tracking (developer tool):

    // wp-config.php
    define('MAXTDESIGN_RBP_PERFORMANCE_MONITORING', true);

    When enabled, the plugin tracks and logs:

  • Cache hit/miss ratios
  • Database query counts and timing
  • Pricing calculation duration
  • Uninstall Behavior

    When the plugin is deleted (not deactivated):

  • Custom database tables dropped (wp_maxtdesign_rbp_rules, wp_maxtdesign_rbp_global_rules)
  • Plugin options removed
  • Custom roles removed (maxtdesign_rbp_* prefixed roles)
  • Transient caches cleared
  • Deactivation preserves all data for reactivation.