Architecture Overview
Xe Plugin is designed around modern PHP standards (PSR-4 autoloading, dependency containerization, and scoped lifecycle loading).
Directory Structure
xe-plugin/
├── assets/ # Frontend and admin static assets (CSS, JS, images)
│ ├── css/
│ │ ├── admin.css # Admin stylesheets
│ │ └── main.css # Frontend stylesheets
│ └── js/
│ ├── admin.js # Admin scripts with localized data
│ ├── authentication.js# AJAX authentication handler
│ └── main.js # Frontend scripts
├── cli/ # PHP CLI tools (Console, Config, Commands)
├── docs/ # MkDocs documentation
├── languages/ # Translation files (.pot, .mo, .po)
├── page-templates/ # Virtual page templates
├── src/ # Core PSR-4 PHP classes (Xe_Plugin\)
│ ├── Admin/ # Admin-specific classes (MenuPages, Assets, Views, Metaboxes)
│ ├── Frontend/ # Frontend-specific classes (Assets, Shortcodes, Views, Product)
│ ├── Modules/ # Business logic modules extending BaseModule
│ ├── Ajax.php # AJAX endpoints
│ ├── Bootstrap.php # Scoped service loader
│ ├── Defaults.php # Default options registry
│ ├── Elementor.php # Elementor auto-loader and category registrar
│ ├── Endpoints.php # Rewrite endpoints router
│ ├── PageTemplates.php # Page template registration
│ ├── Plugin.php # Main container singleton
│ ├── PluginOptions.php # Persistent database options service
│ ├── PostTypes.php # Custom post types
│ ├── Setup.php # Activation, deactivation & auth guards
│ ├── Strings.php # Centralized translation strings
│ ├── Taxonomies.php # Custom taxonomies
│ └── Utils.php # Helper functions
├── stubs/ # Generator stubs
├── templates/ # Endpoint template views (dashboard, header, footer, etc.)
├── config.json # Plugin identity configuration
├── mkdocs.yml # MkDocs configuration
├── xe # CLI runner
└── xe-plugin.php # Plugin main entry point
Autoloading (PSR-4)
The plugin uses Composer's PSR-4 autoloader configured in composer.json:
- Any class inside
src/belongs to theXe_Pluginnamespace and is autoloaded on demand. - CLI commands inside
cli/belong to theXePlugin\CLInamespace.
Execution Lifecycle
- WordPress Loads Plugins: WordPress loads
xe-plugin.php. - Constants & Autoloader: Defines
XE_PLUGIN_FILE,XE_PLUGIN_PATH,XE_PLUGIN_URL,XE_PLUGIN_BASENAMEand includesvendor/autoload.php. - Activation/Deactivation Registration: Binds lifecycle hooks to
Xe_Plugin\Setup::activation()andXe_Plugin\Setup::deactivation(). plugins_loadedHook: Executes_xe_plugin_bootstrap():- Initializes the
Xe_Plugin\Plugincontainer (_xe_plugin()). - Runs
Xe_Plugin\Bootstrap::register(), loading services conditionally based on the current context (Global, Admin, or Frontend).