WP Hoster Agent

The WP Hoster Agent is a custom WordPress plugin installed on each site. It exposes a token-authenticated REST API used for health data and remote actions (flush cache, run cron, etc.). The panel uses the health endpoint during healthchecks to avoid relying solely on WP-CLI.

File paths

PathPurpose
provisioning/wordpress/wphoster-agent/Plugin root (source; rsynced to each site)
provisioning/wordpress/wphoster-agent/wphoster-agent.phpMain plugin file, registers REST routes
provisioning/wordpress/wphoster-agent/includes/class-rest-controller.phpREST controller: health + actions
app/Services/WordPress/WphosterAgentInstaller.phpInstalls plugin and writes token to wp-config

Installation

WphosterAgentInstaller::install() rsyncs the plugin into {site_root}/wp-content/plugins/wphoster-agent, runs wp plugin activate wphoster-agent, generates a 64-char token, and appends to wp-config.php:

Token is stored in site.metadata['agent_token'] so the panel can call the health endpoint.

REST endpoints

Method / PathPurpose
GET /wp-json/wphoster/v1/healthReturns PHP version, memory, WP version, active theme, plugins/themes list, db_size_bytes, disk_usage_bytes, core_checksum_status
POST /wp-json/wphoster/v1/actionsBody: action = flush_cache | run_cron | clear_transients | verify_checksums

Authentication

All routes use permission_callback that checks X-WPHoster-Token header against WPHOSTER_AGENT_TOKEN (constant-time comparison). Missing or invalid token returns 401.

Health response structure (excerpt)

{
  "php_version": "8.2.x",
  "memory_limit": 268435456,
  "memory_usage": 12345678,
  "wp_version": "6.x",
  "active_theme": "Theme Name",
  "active_plugins_count": 5,
  "db_size_bytes": 1234567,
  "disk_usage_bytes": 12345678,
  "agent_version": "1.0.0",
  "plugins": [...],
  "themes": [...],
  "core_checksum_status": "ok" | "modified"
}

Config

KeyPurpose
wphoster.agent.enabledWhether to install agent on provision/clone
wphoster.agent.pathAbsolute path to plugin source (default: base_path('provisioning/wordpress/wphoster-agent'))