Reference for middag-io/wordpress (middag-php-wordpress), the OSS adapter that plugs a WordPress host into middag-io/framework. Backs WP-003 (WordPress is an adapter of the framework’s ports), which applies FW-015 to WordPress.
Who it is for
Developers of a WordPress plugin built on middag-io/framework, and developers who maintain the adapter itself. The adapter is a library: the consumer’s plugin is the composition root (What the adapter is).
Requirements and install
| Item | Value |
|---|---|
| Package | middag-io/wordpress (middag-php-wordpress), Apache-2.0 |
| PHP | ^8.3: 8.3, 8.4 and 8.5, within the PHP versions the WordPress version supports; with the json extension |
| Symfony | ^7.4 || ^8.1 for every Symfony component it requires (contracts and polyfills keep their own ranges) |
| Sibling libraries | middag-io/framework ^1.22 on the 1.x line, then the family MAJOR (^2.0 on 2.x); middag-io/ui comes with the framework |
| WordPress | 7.0 and 7.1 (the latest major and the previous one); the CI runs the integration suite on each |
composer require middag-io/wordpressThe platform rules behind these values are in Platform and Versioning and compatibility, which also states when a WordPress major leaves the range. Wiring the adapter into a plugin is in Configuration & Identity.
Public surface
- Support covers the types tagged
@apionly. Anything untagged, or tagged@internal, may change in any release. A type insrc/with neither tag counts as@internal. API-STABILITY.mdin the repository lists the public surface and points to Versioning and compatibility for the support rules.- The
@apisurface is what a consumer plugin codes against: the REST controller base and theHttp\Contractinterfaces, theDomain\PostandDomain\Userrepositories and meta helpers, theDomain\Taxonomy,Domain\Media,Domain\CommentandDomain\WooCommercevalue objects, the adapter exceptions, thePersistencequery builder, theSettingsandDefinitionbuilders, the@apiSupport layer classes, the mail helpers, the cron registrar, the hook registrar withHook\Contract\HookInterface, the plugin-lifecycle registrar, and the boot diagnostics. - The composition-root concretes are
@apitoo, because the consumer names them when it wires its container:Database\WpdbConnectionAdapter,Database\WpdbSqlDialect,Config\WpConfigResolver,Bus\WpUserContextandPersistence\Query\WpdbConditionCompiler, with the host-context, event-bridge and component-name seams. Type-hint the framework contract in your own code; name the concrete only to wire it. The concretes a consumer never names (Translation\WpTranslator,Runtime\WpMaintenanceGate,Runtime\WpBootstrap) are@internal. - To depend on an
@internaltype, open an issue to have it promoted to@api; promotion is an additive change for a MINOR. - In progress: the generated reference of the
@apisurface is not published yet (Documentation publication).
Changelog, decisions and help
CHANGELOG.mdrecords every release; Releases carry the tags. release-please cuts every release from Conventional Commits; there are no manual tags.- The adapter shares only the MAJOR with the rest of the family: its MINOR and PATCH releases are its own, and its supported WordPress versions belong to it. What each kind of release may carry is in Versioning and compatibility.
- The decision records live in
middag-php-wordpress/docs/decisions. - Questions and bugs: issues of
middag-php-wordpress. Security reports:SECURITY.md; do not open a public issue for a vulnerability.
Pages
- Routing Surfaces — the REST, admin and public rewrite surfaces, and how each one dispatches.
- Controller Bases — the page-controller base, the REST base, and why they do not share a parent.
- Configuration & Identity — the consumer kernel, injected component identity, config prefixes and neutral defaults.
Guides that put this reference to work:
- Getting started with the WordPress adapter — a first plugin: kernel, container, config resolver and a REST controller.
- How-to: REST controllers and routes, Persistence, Repositories, Hooks, Cron, Mail, Definitions and options and Boot diagnostics.
What the adapter is
- A library, not a plugin. It ships no composition root: a WordPress plugin (the consumer) builds the container, binds the ports and boots the kernel.
- It implements framework ports with native WordPress APIs. The full port table, with the OSS default and the Moodle and WordPress implementation of each port, is in Bridge Contracts.
Runtime/WpBootstrap(@internal) is the generic baselineBootstrapInterface. It bindsConfigResolverInterface,UserContextResolverInterface,TranslatorInterface,MaintenanceGateInterface,ConnectionAdapterInterface,SqlDialectInterfaceandHookfileLoaderInterface, plus the syntheticwordpress.wpdbservice. A real consumer overrides what it needs, starting with its own config prefixes (see Configuration & Identity).- It never imports proprietary MIDDAG code. The source scan
tests/AdapterPluginIsolationTest.phpfails the build on a non-OSS MIDDAG namespace, a consumer-plugin namespace or a product table name insrc/.
Bridges are native first
Where WordPress already has the mechanism a port describes, the adapter maps the port onto it instead of running the framework’s in-memory version:
| Port | WordPress mechanism | Note |
|---|---|---|
HostEventBridgeInterface |
do_action / add_action |
WpHostEventBridge turns dispatch('quote.created', [$quote]) into do_action('{prefix}quote.created', $quote). The prefix is a constructor argument with a neutral default. The Moodle adapter delegates to the framework HookManager instead. |
HookfileLoaderInterface |
WP_CONTENT_DIR, active theme, a filter |
WpHookfileLoader loads the hookfile from WP_CONTENT_DIR, then from the active theme, then from the paths returned by its filter. The file name and the filter name follow the neutral defaults. Later sources override earlier ones. |
ConnectionAdapterInterface |
global $wpdb |
See Database. |
MailerInterface |
wp_mail |
WpMailer; Mail/EmailSender looks for templates under the component’s basePath() (templates/emails/), then under the active theme. |
FilesystemInterface |
uploads directory | WpUploadsFilesystem, delegating to the framework LocalFilesystem rooted at wp_upload_dir()['basedir']. |
TranslatorInterface |
__() / _n() |
WpTranslator; the $component argument is the text domain, with a constructor default domain when it is empty (see Configuration & Identity). |
Support layer
src/Support/ holds 25 *Support classes: thin static seams over WordPress functions. Each one isolates a group of host functions so the rest of the adapter never calls them directly, and each degrades to a no-op (or an empty/false result) when WordPress is not loaded, which keeps the adapter unit-testable. Stateless static methods are allowed; static properties are not (see Configuration & Identity).
| Class | Wraps | Surface |
|---|---|---|
AdminSupport |
wp-admin menu and notice APIs | @api |
AssetSupport |
wp_enqueue_script / wp_enqueue_style |
@internal |
CacheSupport |
Object Cache (wp_cache_*) |
@api |
CacheSupportPsr16 |
PSR-16 over the Object Cache, one cache area per wp_cache group (group prefix: a constructor argument with a neutral default) |
@api |
CapabilitySupport |
roles and capabilities write side (add_role, WP_Role::add_cap, …) |
@internal |
CronSupport |
wp_next_scheduled / wp_schedule_event / wp_unschedule_event |
@internal |
EscapeSupport |
esc_html / esc_attr / esc_url |
@internal |
GlobalsSupport |
typed access to $GLOBALS['wpdb'] |
@internal |
HookSupport |
add_action / add_filter / do_action / apply_filters |
@internal |
LifecycleSupport |
register_activation_hook / register_deactivation_hook |
@internal |
LogSupport |
resolves the PSR-3 logger from a container: explicit LoggerInterface, then the framework LoggerFactory, then error_log() |
@internal |
MailSupport |
wp_mail and the wp_mail_from* filters |
@internal |
MetaSupport |
Metadata API for every meta type | @api |
OptionSupport |
get_option |
@api |
PathSupport |
get_stylesheet_directory |
@internal |
PostTypeSupport |
register_post_type / register_taxonomy |
@api |
PrivacySupport |
personal-data exporter and eraser filters | @internal |
RewriteSupport |
add_rewrite_rule / flush_rewrite_rules / get_query_var |
@internal |
SanitizeSupport |
sanitize_text_field, sanitize_key, sanitize_email, sanitize_textarea_field, wp_kses_post |
@internal |
SecuritySupport |
nonce functions | @internal |
SettingsSupport |
Settings API | @internal |
ShortcodeSupport |
Shortcode API | @api |
TransientSupport |
Transients API | @api |
UploadSupport |
wp_upload_dir() |
@api |
UserSupport |
get_current_user_id, current_user_can, user_can, wp_get_current_user |
@internal |
Cron and async jobs
Two separate concerns:
- Recurring events —
Cron/CronRegistrar. A consumer adds events withaddEvent($hook, CronInterval $interval, $callback).CronIntervalis a closed enum (EveryMinute,FiveMinutes,FifteenMinutes,ThirtyMinutes,Hourly,TwiceDaily,DailyMorning), so an unknown recurrence fails at compile time instead of scheduling nothing. The custom intervals are registered on thecron_schedulesfilter under keys of the form{component}_{case}, so two plugins in one request keep independent schedules. Interval labels go through the hostTranslatorInterface. The consumer kernel callsregister()oninit(priority 5) when the container binds the registrar. - One-off async jobs —
Cron/Contract/JobSchedulerInterface.enqueue($hook, $args)queues a job that fires the action hook out of band.Cron/JobScheduler::make($group, $actionScheduler)picks the driver at call time:ActionSchedulerDriverwhenas_enqueue_async_action()exists (Action Scheduler, bundled with WooCommerce or installed on its own: persistent queue, retries, admin UI, WP-CLI runner), otherwiseWpCronDriver(wp_schedule_single_event; pseudo-cron, no retry, identical hook and arguments within ten minutes are suppressed). Build the scheduler afterplugins_loaded, or detection misses an Action Scheduler loaded by another plugin.
Locking, retries beyond the driver’s own and job governance are not part of the adapter.
WooCommerce
WooCommerce is optional and never a Composer dependency.
Domain/WooCommerce/WooCommerceAvailability::isAvailable()probes at runtime (class_exists('WooCommerce')orfunction_exists('WC')).Domain/WooCommerce/OrderReferenceandProductReferenceare lightweight read-only references that do not need WooCommerce loaded.Security/Enum/WooCommerceCapabilitylists the native WooCommerce capability strings next toWpCapability. Referencing a case never needs WooCommerce; granting one only matters once its roles (for exampleshop_manager) exist.- Action Scheduler, which WooCommerce bundles, is the preferred async job driver when present (see above).
Payments, webhooks and store integrations are not in this adapter.
Database ($wpdb)
Database/WpdbConnectionAdapter(@api) is the only object in the adapter that knows$wpdb. Everything above it (query builders, repositories, domain) depends on the frameworkConnectionAdapterInterface. Records and conditions are associative arrays; rows come back asARRAY_A.Database/WpdbSqlDialect(@api) is MySQL/MariaDB. WordPress raw SQL uses physical table names, sotable()prepends the$wpdb->prefix(wp_,wp_2_, …) instead of bracing the name as Moodle does. The connection adapter builds its own prefixed dialect from$wpdb->prefix, andWpBootstrapresolvesSqlDialectInterfaceto that same instance. The record helpers on the connection adapter (insert(),update(),delete(),find(),findAll()) accept a logical or an already-prefixed name and add the prefix when it is missing.- Capabilities reported by
supports():
Capability |
Reported | Why |
|---|---|---|
Transactions |
yes | $wpdb runs START TRANSACTION / COMMIT / ROLLBACK; meaningful only on InnoDB |
Streaming |
no | no unbuffered cursor; results are buffered |
JsonWhere |
yes | MySQL 5.7+/8.0 JSON predicates |
Returning |
no | MySQL has no RETURNING |
Upsert |
yes | INSERT ... ON DUPLICATE KEY UPDATE |
SchemaDiff |
no | WordPress owns its schema through dbDelta() |
RowLock |
yes | InnoDB SELECT ... FOR UPDATE / FOR SHARE |
- Schema. The adapter ships no DDL adapter: WordPress owns its schema lifecycle through
dbDelta().Persistence/VersionTrackerstores a schema version per library in awp_optionsrow written withautoload = false. - Native content.
Domain/Post/PostRepository,PostMetaRepository,Domain/User/UserRepositoryandUserMetacoverwp_posts,wp_postmetaand users;Persistence/QueryBuilderbuildsWP_Query-backed reads overwp_posts.
Boot diagnostics
Diagnostics/ is a post-autoload self-check: it proves that the packages built on the adapter loaded and booted, and gives health checks and pipelines a WP-CLI command to gate on. A URL that answers 200 does not prove that a plugin booted.
- Registration.
DiagnosticsRegistryholds a WordPress filter name (neutral defaultmiddaglib_diagnostics).register(PackageProbe $probe)adds the probe on that filter, so every plugin and theme that shares the filter name meets in one report, although each boots its own kernel. There is no static registry. PackageProbe. A package name, its version, its kernel class, an optional entry class, an optional autoloader path and extra checks. It holds names only: declare it from the main plugin file, before the kernel boots, so a failed boot shows up as a failed check instead of a missing package.BootReport. Per package, it checks that the entry class resolves (and from which file), which autoloader file the bootstrap chose when the package declares one, that the kernel booted (it readsisBooted()and never boots it) and that a version was declared, then runs the package’s own checks. A check that throws becomes a failure and the next check still runs. An expected package that never registered, an entry on the filter that is not a probe, a duplicate name, or no package at all fail the report.- Host-level checks.
Contract\DiagnosticCheckInterface, withCallbackCheckas a closure shorthand, adds a check with aCheckScopeofBootorRender. A render check covers what boot cannot see, for example that an admin page still emits the HTML shell and the core script bundles. Until a render check runs, the text and JSON output say that the report covers boot only. - WP-CLI.
DoctorCommandRegistrarregisterswp <root> doctor(neutral rootmiddaglib; the consumer passes its own). The command takes--expect=a,b,--strict(warnings fail too) and--format=text|json, and exits0when healthy and1when broken. Outside WP-CLI,register()does nothing. Register the command from the main plugin file, so it exists when the kernel fails to boot.
$registry = new DiagnosticsRegistry('acme_diagnostics');
$registry->register(new PackageProbe('acme-shop', ACME_SHOP_VERSION, AcmeShopKernel::class));
(new DoctorCommandRegistrar(new DoctorCommand($registry, ['acme-shop']), 'acme'))->register();A health gate passes the full list of packages it expects: wp acme doctor --expect=acme-shop,acme-quotes. The list given to the constructor only applies when the package that registered the command loaded, so it cannot catch that package’s own absence.
Out of scope by design
- Token authentication. No bearer-token or JWT code ships here (guard:
tests/Architecture/NoBundledTokenAuthTest.php). REST controllers depend onRequestAuthenticatorInterface; the defaultWpSessionAuthenticatorresolves the WordPress session only. A consumer that accepts tokens composes and injects its own authenticator. See Routing Surfaces. - Governed concerns. Item/EAV storage, query engine, audit and activity feeds, outbox, tenancy, rate limits, scopes, payments, webhooks and CRM live in proprietary packages downstream.
- Widgets and
admin-ajax.php. Noregister_widget/WP_Widgetand noadmin-ajaxaction handlers: consumers reach the front end through the three routing surfaces and the Inertia glue.