Skip to content

Boot Sequence

Harish Dhanraj Sugandhi edited this page Mar 4, 2026 · 1 revision

Boot Sequence

Entry Point

The plugin loads via openwp.php which defines constants and delegates to the Loader class:

openwp.php
  ├── Define OPENWP_FILE, OPENWP_BASE, OPENWP_DIR, OPENWP_URL, OPENWP_VERSION
  ├── require constants.php
  ├── require loader.php
  └── OpenWP\Loader::get_instance()

Loader Class (loader.php)

The Loader is a singleton that orchestrates the entire boot process.

Constructor

private function __construct() {
    spl_autoload_register([$this, 'autoload']);    // PSR-4 autoloader
    register_activation_hook(OPENWP_FILE, [$this, 'activation']);
    register_deactivation_hook(OPENWP_FILE, [$this, 'deactivation']);
    add_action('plugins_loaded', [$this, 'boot']);
    add_action('init', [$this, 'load_textdomain']);
}

Activation (activation())

Runs once when the plugin is activated:

  1. Capability_Manager::grant_capabilities() - Grants openwp_run_agent and openwp_manage_settings to administrators
  2. Migrations::activate() - Creates all 5 custom tables via dbDelta
  3. Onboarding_State::initialize_defaults() - Sets up first-run state
  4. Onboarding_State::set_redirect_flag(true) - Triggers redirect to onboarding

Deactivation (deactivation())

Cleans up:

  • wp_clear_scheduled_hook('openwp_cleanup_backups') - Removes cron schedule

Boot Sequence (boot())

Runs on plugins_loaded hook:

1. Capability_Manager::grant_capabilities()
2. Migrations::maybe_upgrade()        ← DB schema versioning
3. Onboarding_State::initialize_defaults()

   ┌─ Is multisite? ──► Show admin notice and STOP
   │
   └─ Single site ──►
      4. Action_Bootstrap::get_instance()  ← Register 50+ actions
      5. Ability_Bootstrap::get_instance() ← WordPress Abilities API bridge
      6. Api_Init::get_instance()          ← REST API routes (openwp/v1)
      7. MCP_Server::get_instance()        ← MCP routes (mcp/v1)
      8. Admin_Page::get_instance()        ← WP admin menu + assets
      9. Editor_Block::get_instance()      ← Gutenberg block
     10. Sitewide_Chatbot::get_instance()  ← Frontend chatbot widget
     11. Schedule cleanup cron (hourly)

Cron Jobs

The boot sequence schedules an hourly cleanup:

  • openwp_cleanup_backups - Runs three cleanup tasks:
    • Backup_Service::cleanup_expired_backups() - Delete expired backup files
    • Log_Repository::cleanup_retention() - Purge old audit logs
    • Attachment_Service::cleanup_expired_files() - Remove temp chatbot uploads

Autoloader

PSR-4 style autoloader for the OpenWP\ namespace:

// Maps: OpenWP\Inc\Actions\Content_Actions
// To:   {plugin_dir}/inc/Actions/Content_Actions.php

The Inc\\ prefix in the namespace maps to the inc/ directory. All other namespace segments map directly to directory paths.

Constants (constants.php)

Constant Default Purpose
OPENWP_DB_VERSION '1.0.0' Database schema version
OPENWP_OPTION_SETTINGS 'openwp_settings' Main settings option key
OPENWP_OPTION_PROVIDER_KEYS 'openwp_provider_keys' Encrypted API keys
OPENWP_OPTION_ACTION_POLICIES 'openwp_action_policies' Per-action policy overrides
OPENWP_OPTION_RATE_LIMITS 'openwp_rate_limits' Rate limit configuration
OPENWP_OPTION_DB_VERSION 'openwp_db_version' Stored DB version
OPENWP_OPTION_ONBOARDING_COMPLETED 'openwp_onboarding_completed' Onboarding flag
OPENWP_OPTION_MCP_ENABLED 'openwp_mcp_enabled' MCP server toggle
OPENWP_OPTION_MCP_BEARER_TOKEN 'openwp_mcp_bearer_token' MCP auth token
OPENWP_OPTION_MCP_DEBUG_MODE 'openwp_mcp_debug_mode' MCP debug toggle
OPENWP_OPTION_MCP_MODULES 'openwp_mcp_modules' MCP module toggles
OPENWP_DISABLE_AGENT false Kill switch for agent execution
OPENWP_DISABLE_NO_ACTION_RECOVERY false Disable no-action recovery

Clone this wiki locally