5.4 KiB
Copilot Instructions for V-WordPress-Plugin-Updater
Architecture Overview
This repository contains a dual-component WordPress updater system:
- Update API Server (
v-update-api/): standalone PHP web service that hosts and serves plugin/theme ZIP updates. - WordPress Client Plugin (
v-wp-updater/): WordPress plugin that checks the API and installs updates.
Both components are independently deployable.
Namespaces (Do Not Mix)
- API server code uses
App\... - WordPress plugin code uses
VWPU\...
Current API Server Architecture (v-update-api)
Core Classes
v-update-api/app/Core/ currently contains:
DatabaseManager.phpErrorManager.phpRequest.phpResponse.phpRouter.php
Important: there is no SessionManager, ResponseManager, or Controller base class in the current architecture.
Request/Response Pattern
App\Core\Request::fromGlobals()parses the URL path and builds a request object.App\Core\Router::dispatch()returns anApp\Core\Response.public/index.phpsends the returned response via$response->send().- Prefer
Responsestatic factories:Response::view()Response::redirect()Response::text()Response::json()Response::file()Response::html()
Session and Security Helpers
Session/auth logic is implemented through App\Helpers\SessionHelper (static helper), not a singleton session manager.
- Initialize/access session values with
SessionHelper::get()/SessionHelper::set(). - Validate auth session with
SessionHelper::isValid(). - Regenerate session after successful login with
SessionHelper::regenerate(). - CSRF token is initialized in
public/index.phpif missing.
Error Handling
App\Core\ErrorManager is a singleton that registers error/exception/shutdown handlers and provides centralized logging.
Routing and Controller Conventions
Router Behavior
App\Core\Router:
- Uses FastRoute (
FastRoute::recommendedSettings(...)). - Protects all non-login, non-API routes with auth checks.
- Applies CSRF checks to non-GET/HEAD/OPTIONS requests outside
/api. - Returns
Responseobjects from dispatch.
Registered Routes
/→ redirect to/home/login(GET,POST)/home(GET,POST)/plupdate(GET,POST)/thupdate(GET,POST)/logs(GET,POST)/api(router accepts multiple methods;ApiControllerenforcesGET)
Controller Contract
Controllers return App\Core\Response instances.
Do not use raw echo, header(), or exit for normal request flow.
API Contract and Data Model
Update API (/api)
Expected query parameters:
type(pluginortheme)domainkeyslugversion
ApiController behavior:
200: newer ZIP available (streams file)204: no update available400: missing/invalid params403: authentication failure, blacklisted IP, or invalid/missing client IP404: authenticated request references unknown slug405: non-GET method500: update file unavailable/unreadable
Storage and Sync
- SQLite DB:
v-update-api/storage/updater.sqlite - Key tables:
plugins,themes,hosts,logs,blacklist cron.phpsyncs filesystem ZIP metadata to DB and cleans blacklist records
Update Package Naming
ZIP filenames must use:
{slug}_{version}.zip (example: my-plugin_1.2.3.zip)
Encryption and Auth Notes
- Host API keys are stored encrypted via
App\Helpers\EncryptionHelper. - Current implementation uses AES-256-GCM with legacy CBC migration support.
ENCRYPTION_KEYis read fromv-update-api/config.phpconstant.- Blacklist behavior:
- Blacklisted entries expire after 7 days.
- Non-blacklisted stale entries are pruned after 3 days.
WordPress Client Plugin (v-wp-updater)
Options and Defaults
Plugin options are managed through VWPU\Helpers\Options with vwpu_ prefix.
Canonical keys:
update_pluginsupdate_themesupdate_keyupdate_plugin_urlupdate_theme_url
Stored option names in WP are vwpu_<key> (for example, vwpu_update_key).
Scheduled Hooks
vwpu_plugin_updater_check_updatesvwpu_theme_updater_check_updates
Both are scheduled daily on install; each handler checks enablement flags before running.
Updater Behavior
PluginUpdater and ThemeUpdater:
- call the API with
type,domain,slug,version,key - handle statuses
200,204,403, others as error - prefetch ZIP bodies on
200and reuse local temp file during install to avoid duplicate downloads
Setup and Operations
API Server Setup (Current)
- Set
v-update-api/public/as web root. - Configure
v-update-api/config.phpconstants:VALID_USERNAMEVALID_PASSWORDENCRYPTION_KEYSESSION_TIMEOUT_LIMIT
- Ensure
v-update-api/storage/is writable. - Run
v-update-api/public/install.phpto initialize schema. - Schedule cron to run
php v-update-api/cron.php(CLI only, no worker flag).
Test and Quality Commands
From repository root:
vendor/bin/phpunitvendor/bin/phpcsvendor/bin/phpcbfvendor/bin/phpstan
Documentation Sync
When behavior changes, update in this order:
- Code
- Tests (
tests/) CHANGELOG.md(notable changes)README.md(if setup/usage/API changed).github/copilot-instructions.md(architecture/conventions changes)
Also follow AGENTS.md checklist before submission.