WB Ad Manager follows a modular architecture built on WordPress best practices. This guide explains the plugin’s internal structure, the Singleton pattern used across all core classes, and how modules are loaded during initialization.
Understanding the architecture will help you extend the plugin effectively and write code that integrates cleanly with the existing system.
Plugin Structure
wb-ads-rotator-with-split-test/
├── wb-ads-rotator-with-split-test.php # Main plugin file
├── includes/
│ ├── Core/ # Core functionality
│ │ ├── class-plugin.php # Main plugin class
│ │ ├── class-installer.php # Database setup
│ │ ├── class-cpt.php # Custom post type
│ │ └── trait-singleton.php # Singleton pattern
│ │
│ ├── Admin/ # Admin functionality
│ │ ├── class-admin.php # Metaboxes, columns
│ │ ├── class-settings.php # Settings page
│ │ └── class-help-docs.php # Help documentation
│ │
│ ├── Frontend/ # Frontend functionality
│ │ └── class-frontend.php # Assets, tracking
│ │
│ └── Modules/ # Feature modules
│ ├── AdTypes/ # Ad type handlers
│ ├── Placements/ # Placement handlers
│ ├── Targeting/ # Targeting engine
│ ├── GeoTargeting/ # Geo-location
│ └── Links/ # Link management
│
├── assets/ # CSS/JS files
├── templates/ # Template files
└── languages/ # Translation files
Constants
The plugin defines several global constants you can use in your extensions:
// Plugin version
WBAM_VERSION
// Plugin file path
WBAM_FILE
// Plugin directory path
WBAM_PATH
// Plugin URL
WBAM_URL
Requirements
- WordPress 5.8+
- PHP 7.4+
Singleton Pattern
All main classes use the Singleton pattern via a shared trait. This ensures only one instance of each class exists throughout the request lifecycle:
use WBAM\Core\Singleton;
class My_Class {
use Singleton;
public function init() {
// Initialization code
}
}
// Usage
My_Class::get_instance()->init();
Module Loading
Modules are loaded in the main plugin class during the wbam_init action. You can hook into module initialization to register your own extensions or run custom setup logic:
// Hook into module initialization
add_action( 'wbam_init', function() {
// Your initialization code
}, 10 );
The plugin fires several registration actions during initialization:
wbam_init— Main initialization hook, fires after all core modules are loaded.wbam_register_ad_types— Use this to register custom ad type handlers.wbam_register_placements— Use this to register custom placement types.wbam_placements_init— Fires after all placements are registered and ready.
