Plugin Architecture
Class Structure
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_TIMESTAMPIndexes: 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_TIMESTAMPIndexes: 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 TTLIn-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 trackingA 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:
Uninstall Behavior
When the plugin is deleted (not deactivated):
wp_maxtdesign_rbp_rules, wp_maxtdesign_rbp_global_rules)maxtdesign_rbp_* prefixed roles)Deactivation preserves all data for reactivation.