A shared PHP base for WordPress projects, distributed as a Composer package
(rtcamp/wp-framework). It ships the contracts, loaders, and
utilities that plugins and themes boot through — so you write intent instead
of registration boilerplate.
wp-framework is a library, not a plugin. It ships contracts (interfaces,
abstracts, traits) plus concrete loaders and utilities; consuming plugins and
themes build their features on top. Zero runtime dependencies. PHP 8.2+.
composer require rtcamp/wp-frameworkPSR-4 autoloading: rtCamp\WPFramework\ → inc/.
- Registration core — the spine every consumer boots through:
Registrable,ConditionallyRegistrable,Shareable,CLICommandinterfaces- the
Loadertrait (instantiate a list of classes, register their hooks, cache the shared ones) and theContainerit stores instances in
- Ten
Abstract*base classes — one per WordPress registration chore, so a consumer writes intent instead of boilerplate:AbstractModule,AbstractPostType,AbstractTaxonomy,AbstractBlock,AbstractShortcode,AbstractRESTController,AbstractSettingsPage,AbstractAdminPage,AbstractUserRole,AbstractFeature - Asset & render loaders —
AssetLoader(scripts/styles/modules +*.asset.phpmanifests),ComponentLoaderandTemplateLoader(resolve components/templates across the child-theme → parent-theme → package hierarchy) Singletontrait — standardget_instance()with clone/wakeup guards- Utilities & services (
inc/Utils/) — context-scoped helpers:Encryptor— authenticated AES-256-GCM encryption for values stored in the DBCache— typed wrapper over the WP object cache, group-namespaced, optional SWRFeatureSelector+FeatureSelectorSettingsPage— a fail-closed feature-flag registry and its admin toggle page
The contract surface (inc/Contracts/) is the public API: every interface,
abstract, and signature there is consumed by dependents, so changes to it are
treated as breaking.
- No bootstrap /
Mainclass. The framework gives you theLoadertrait and the contracts; each consumer writes its own entry class that kicks off the firstload(). The framework is the spine, not the application. - No project scaffolding engine. Scaffold/init tooling lives in a separate
package (
@rtcamp/wp-tooling), not here.
Start with docs/index.md, then:
| Doc | What it covers |
|---|---|
| architecture.md | How a class becomes a live hook — the Registrable → Loader → Container flow. Read first. |
| contracts.md | The interfaces and traits in detail. |
| abstracts.md | Cookbook for the Abstract* base classes. |
| loaders.md | AssetLoader, ComponentLoader, TemplateLoader and the theme-override hierarchy. |
| utilities.md | Encryptor, Cache, FeatureSelector, and Container. |
composer install # PHP dev dependencies
composer check # lint (PHPCS) + analyse (PHPStan) + test (PHPUnit)Tests run against real WordPress via @wordpress/env
(npm install && npm run wp-env start). TDD: a failing test first (tests/ mirrors
inc/), then the code. Conventions live in AGENTS.md, shared across
all contributors and AI tools.
See CONTRIBUTING.md.
GPL-2.0-or-later © rtCamp
