Skip to content

Architecture

webdesign29 edited this page Jun 13, 2026 · 2 revisions

Architecture

bext-wp is a small, dependency-free, namespaced (Bext\WP) plugin with a custom autoloader.

Boot

bext-wp.php (normal plugin)   or   mu-loader.php → bext-wp/bext-wp.php (must-use)
        │
        ▼
Plugin::instance()->boot()
        │  builds Env, then registers modules
        ├── always:  Settings, Admin, Health   (so the UI always exists)
        └── gated:   Cache, Cron, SDK          (Env::is_enabled)

Each module exposes register() and is expected to no-op when not behind bext and fail open on any bext call.

Files

File Responsibility
bext-wp.php Plugin header, constants, autoloader, boot, deactivation cleanup
mu-loader.php must-use stub that requires the package from its subdirectory
uninstall.php removes all bext_wp_* options (multisite-aware)
src/Plugin.php singleton orchestrator; boots modules
src/Env.php config resolution (constant > setting > default) + loopback/cloud transport
src/Settings.php wp-admin Settings page (option bext_wp_settings)
src/Cache.php purge-on-change + personalization-safe headers + manual purge
src/Cron.php Action Scheduler taming + queue stats
src/Health.php config checks + PHP-warning capture
src/Admin.php dashboard + admin-bar pill
src/SDK.php wp_mail + job bridge
src/Network.php multisite network-admin settings + cross-site dashboard/purge (loads only on multisite)
cli/Commands.php wp bext …
bin/deploy-fleet.sh copy-per-site installer

Env: the hub

Env is the one place that knows how to talk to bext:

  • Configmode(), is_enabled(), app_id(), purge_on_save_enabled(), anon_cache_control(), sdk_email_enabled(), sdk_jobs_enabled(), cloud getters — each layered constant > setting > default.
  • Detectionis_behind_bext() (param / header / sticky flag / mode).
  • Transportendpoint_base() (loopback 127.0.0.1:80 vs cloud URL) + transport_headers() (Host, and Authorization: Bearer in cloud mode), used by purge_proxy(), sdk_request(), bext_get().

State

Option Autoload Purpose
bext_wp_settings yes the Settings page values
bext_wp_detected yes sticky "we've seen a bext signal" flag (auto mode)
bext_wp_purge_log no recent purges (dashboard)
bext_wp_recent_warnings no captured PHP warnings (dashboard)

Transient bext_wp_test_result holds the last Test connection outcome (60 s).

bext-side touchpoints

  • BEXT_SERVER FastCGI param → detection.
  • POST /__bext/cache/purge-proxyfastcgi_cache.invalidate_paths/prefix (the real eviction).
  • BEXT_PURGE_TOKEN env → opt-in bearer auth for remote (cloud) purges.
  • /__bext/sdk/* (email/queue), /__bext/health → SDK + dashboard.

Compatibility

PHP 7.4+ (no 8.0-only syntax). Multisite-aware (per-blog options; subdirectory full-purge scoped to the blog path). Works with or without WooCommerce / Action Scheduler.

Clone this wiki locally