Skip to content

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:

{
  "autoload": {
    "psr-4": {
      "XePlugin\\CLI\\": "cli/",
      "Xe_Plugin\\": "src/"
    }
  }
}
  • Any class inside src/ belongs to the Xe_Plugin namespace and is autoloaded on demand.
  • CLI commands inside cli/ belong to the XePlugin\CLI namespace.

Execution Lifecycle

  1. WordPress Loads Plugins: WordPress loads xe-plugin.php.
  2. Constants & Autoloader: Defines XE_PLUGIN_FILE, XE_PLUGIN_PATH, XE_PLUGIN_URL, XE_PLUGIN_BASENAME and includes vendor/autoload.php.
  3. Activation/Deactivation Registration: Binds lifecycle hooks to Xe_Plugin\Setup::activation() and Xe_Plugin\Setup::deactivation().
  4. plugins_loaded Hook: Executes _xe_plugin_bootstrap():
  5. Initializes the Xe_Plugin\Plugin container (_xe_plugin()).
  6. Runs Xe_Plugin\Bootstrap::register(), loading services conditionally based on the current context (Global, Admin, or Frontend).