Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
/CLAUDE.md linguist-documentation export-ignore
/CHANGELOG.md linguist-documentation export-ignore

# Ship on purpose: README.md and LICENSE.md, inc/, plus ai/ and bin/sync-ai-instructions.js, which consumers run from vendor/ via `npm run sync-ai`.
# These are intentionally shipped.
/LICENSE.md linguist-documentation
/README.md linguist-documentation
13 changes: 2 additions & 11 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@ body:
- type: markdown
attributes:
value: >-
Thanks for the suggestion. Please search
[existing issues](https://github.com/rtCamp/wp-primitives/issues?q=is%3Aissue)
first.
- type: markdown
attributes:
value: >-
`inc/Contracts/` is public API: every rtCamp plugin and theme consumes
it, so changing a signature there is a breaking change. The package also
keeps zero Composer runtime dependencies.
[CONTRIBUTING.md](https://github.com/rtCamp/wp-primitives/blob/main/.github/CONTRIBUTING.md)
explains how to build it yourself.
Thanks for the suggestion. Please search [existing issues](https://github.com/rtCamp/wp-primitives/issues?q=is%3Aissue) first.
See [CONTRIBUTING.md](https://github.com/rtCamp/wp-primitives/blob/main/.github/CONTRIBUTING.md) for contribution guidelines.
- type: dropdown
id: area
attributes:
Expand Down
6 changes: 3 additions & 3 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

## Reporting a vulnerability

Please do not report security issues in public issues, pull requests or discussions.
In the interest of responsible disclosure, please **do not** report security issues in public issues, pull requests or discussions.

Report them privately through GitHub instead: open the repository's **Security** tab and choose **Report a vulnerability**, or go straight to <https://github.com/rtCamp/wp-primitives/security/advisories/new>. The report stays visible only to you and the maintainers, and the fix, the release and the advisory are coordinated in that same thread.
Instead, report security issues privately through GitHub: open the repository's **Security** tab and choose **Report a vulnerability**, or go to <https://github.com/rtCamp/wp-primitives/security/advisories/new>.

Include what you can of:
Make sure to include as much as you can of:

- the affected class or method and the package version;
- the impact, and the conditions an attacker needs;
Expand Down
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Detailed rules: `.github/instructions/php.instructions.md`.

## Review conduct

- **One comment per distinct issue** Distinct problems get separate comments, even on the same line. A single root cause spanning lines → posted once at the clearest line.
- **One comment per distinct issue.** Distinct problems get separate comments, even on the same line. Post a single root cause spanning lines once, at the clearest line.
- **Always post the missing-tests finding** when a new/changed class ships without a matching test in `tests/phpunit/Integration/`. Mandatory; exempt from dedupe/trim/comment-budget.
- **Order by impact:** backward-compatibility/contract break → correctness → security → style.
- **On a correct, deliberate implementation, don't manufacture findings.** Prefer zero comments over low-value ones. A clean PR comes back clean.
12 changes: 6 additions & 6 deletions .github/instructions/php.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Everything under `inc/Contracts/` is a **consumed contract**. New abstracts/inte

## Flag on review (priority order)

1. 🚩 **MANDATORY: always post, exempt from dedupe/trim/budget:** a new or changed class/trait/interface shipped without a matching test in `tests/phpunit/Integration/`.
2. 🚩 Backward-incompatible change to anything under `inc/Contracts/` (renamed/removed/retyped public method, changed abstract signature) without a documented migration. This breaks every consumer.
3. 🚩 A new dependency added to `composer.json` `require` (must stay `php`-only; dev tools go in `require-dev`).
4. 🚩 Missing `strict_types`/types/docblocks; PSR-4 mismatch; `self::` where `static::` is required.
5. 🚩 Missing escape/sanitize where the utility touches WordPress output/input; raw `$wpdb` without `prepare()`.
6. 🚩 New abstract/interface that doesn't follow the existing contract shape (e.g. an `Abstract*` not implementing `Registrable`, or duplicating a capability the `Loader`/`Container` already provides).
1. **MANDATORY: always post, exempt from dedupe/trim/budget:** a new or changed class/trait/interface shipped without a matching test in `tests/phpunit/Integration/`.
2. Backward-incompatible change to anything under `inc/Contracts/` (renamed/removed/retyped public method, changed abstract signature) without a documented migration. This breaks every consumer.
3. A new dependency added to `composer.json` `require` (must stay `php`-only; dev tools go in `require-dev`).
4. Missing `strict_types`/types/docblocks; PSR-4 mismatch; `self::` where `static::` is required.
5. Missing escape/sanitize where the utility touches WordPress output/input; raw `$wpdb` without `prepare()`.
6. New abstract/interface that doesn't follow the existing contract shape (e.g. an `Abstract*` not implementing `Registrable`, or duplicating a capability the `Loader`/`Container` already provides).
17 changes: 8 additions & 9 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Labels for rtCamp/wp-primitives.
#
# Labels are repository settings, not files, so adding an entry here does not
# create the label. A maintainer applies this list by running
# To apply these labels to the repository, run
# `gh label create <name> --color <color> --description <description> --force`
# for each entry: missing labels are created and existing ones updated. That
# never deletes a label, so removing an entry here does not remove it on GitHub.
# for each entry, which creates missing labels and updates existing ones.
#
# To remove an existing label, you must delete it manually on GitHub or use
# `gh label delete <name>`
#
# The "Shared" sections are the same in all five rtCamp framework repositories
# (wp-shared-workflows, wp-primitives, wp-tooling, theme-elementary and
# plugin-elementary), apart from the wording of the BC descriptions; change them
# in all five together. The sections after them belong to this repository.
# .github/release.yml groups release notes by these labels.
# plugin-elementary), and should be changed together across all repositories.

# --- Shared: type ------------------------------------------------------------
- name: 'Type: Bug'
Expand Down Expand Up @@ -104,15 +103,15 @@
description: 'Shared traits (Singleton)'
- name: 'Scope: Quality Config'
color: '0075CA'
description: 'phpcs.xml.dist + phpstan.neon.dist'
description: 'phpcs.xml.dist and phpstan.neon.dist'
- name: 'Scope: Tests'
color: 'BFDADC'
description: 'PHPUnit test suite'
- name: 'Scope: Docs'
color: 'FEF2C0'
description: 'Documentation'

# --- Legacy: keep until relabelled -------------------------------------------
# --- wp-devtools: keep until relabelled --------------------------------------
# These describe wp-devtools code that is not in this package. They are still on
# closed issues, so they stay until those are relabelled; don't use them on new
# issues.
Expand Down
31 changes: 0 additions & 31 deletions .github/release.yml

This file was deleted.

11 changes: 4 additions & 7 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Dependabot auto-merge

# GitHub's documented pattern: run on the Dependabot pull request itself (no
# workflow_run, no checkout), read the update type from Dependabot's metadata and
# enable auto-merge for minor and patch updates. Auto-merge then waits for every
# ruleset requirement, so the "Test and Measure" jobs must be required status
# checks for a red run to block the merge.
# Enables auto-merge for Dependabot minor and patch updates.
#
# Repository prerequisites (Settings): "Allow auto-merge" enabled, and the main
# ruleset's required reviews satisfiable for Dependabot pull requests.
# Requires "Allow auto-merge" in the repository settings, and the "Test and Measure" jobs as required
# status checks so a failing run blocks the merge.
# @see https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions

on: pull_request

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ jobs:

- name: Build documentation
id: docs
# Pinned to a commit: the action's code only lives on the unmerged
# codex/documentation-workflow branch (rtCamp/action-docusaurus-build#1).
# Move to a release tag once that PR merges and is tagged.
# @todo Switch to a release tag commit once the Action is merged and tagged.
# @see https://github.com/rtCamp/action-docusaurus-build#1.
uses: rtCamp/action-docusaurus-build@b671d6800c68a74da8913edb9321422fe8afaedc # codex/documentation-workflow, 2026-09-17
with:
site-title: ${{ vars.DOCS_SITE_TITLE }}
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: PR Title Validation

# Pull requests are squash-merged and the PR title becomes the commit on main. release-please
# reads those subjects to pick the next version and write CHANGELOG.md, so the title has to be a
# Conventional Commit: feat -> minor, fix -> patch, a "!" after the type -> major.
#
# Not a required status check: the release pull request is opened with GITHUB_TOKEN, which
# starts no workflow runs, so this check never reports on it.
# Ensures PR titles follow the Conventional Commit format, so they can be used during release notes generation.

on:
pull_request:
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
name: Release

# release-please reads the Conventional Commit subjects squash-merged to main and keeps one
# release pull request open that bumps the version and writes CHANGELOG.md. Merging that pull
# request tags vX.Y.Z on main and publishes the GitHub release with the changelog entry as notes.
#
# The release pull request is opened with GITHUB_TOKEN, so GitHub starts no workflow runs on it
# (no tests, no PR title check). Keep the PR title check out of the required checks. If the Test
# and Measure jobs become required, as auto-merge.yml expects for Dependabot, a release pull
# request waits on checks that never start: switch the token below to a GitHub App token, which
# starts them, or have a maintainer push an empty commit to the release branch, which does too.
# Opens the release pull request and publishes releases with release-please.
# @see docs/maintainers.md#releasing

on:
push:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/vendor/
/node_modules/

# macOS/IDE
# OS and editor files
.DS_Store
Thumbs.db
.idea/
Expand All @@ -16,7 +16,7 @@ Thumbs.db
tests/_output/*
!tests/_output/.gitkeep

# Local Configs
# Local config overrides
/phpcs.xml
/phpunit.xml
/phpstan.neon
Expand Down
8 changes: 1 addition & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# CLAUDE.md

Read **[AGENTS.md](AGENTS.md)**: it is the source of truth for this repo's conventions, shared across all AI tools (Claude Code, Copilot, Codex). The detailed rules it points to live in `.github/`.

Claude-specific notes:

- _(none currently; keep Claude overrides here if they ever diverge from AGENTS.md)_
@AGENTS.md
116 changes: 12 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,128 +7,36 @@
</p>

<p align="center">
A shared PHP base for WordPress projects, distributed as a Composer package
(<code>rtcamp/wp-primitives</code>). It ships the contracts, loaders, and
utilities that plugins and themes boot through — so you write intent instead
of registration boilerplate.
Shared bases classes, loaders, and utilities for WordPress plugins and themes, distributed as the Composer package <code>rtcamp/wp-primitives</code>.
</p>

---

`wp-primitives` 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. It has **zero Composer runtime dependencies**.
`wp-primitives` is a zero-dependency **Composer library** meant to be consumed by WordPress plugins and themes. It requires PHP 8.2+ and WordPress 6.5+, and has no Composer runtime dependencies.

Requirements:
The library provides:

- PHP 8.2+
- WordPress 6.5+
- Composer
- The OpenSSL PHP extension when using `Encryptor`
- Shared base classes for WordPress objects like post types, blocks, and settings pages.
- Loaders to manage the lifecycle of these objects.
- Utility functions and traits to simplify common tasks in WordPress development.

## Install
## Quick Start

```bash
composer require rtcamp/wp-primitives:^2.0
composer require rtcamp/wp-primitives
```

The package is published on [Packagist](https://packagist.org/packages/rtcamp/wp-primitives), so no extra configuration is needed. To install straight from GitHub instead (a branch, a fork, or a project that does not use Packagist), add a VCS repository before requiring it:
For more details on requirements, installation, and usage, see [Getting started](docs/getting-started.md).

```json
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/rtCamp/wp-primitives" }
]
}
```

PSR-4 autoloading: `rtCamp\WPPrimitives\` → `inc/`.

## Quick look

```php
use rtCamp\WPPrimitives\Contracts\Abstracts\AbstractPostType;
use rtCamp\WPPrimitives\Contracts\Traits\Loader;
use rtCamp\WPPrimitives\Contracts\Traits\Singleton;

final class ArticlePostType extends AbstractPostType {
public static function get_slug(): string { return 'article'; }
public function get_singular_label(): string { return __( 'Article', 'acme' ); }
public function get_plural_label(): string { return __( 'Articles', 'acme' ); }
public function get_menu_icon(): string { return 'dashicons-media-document'; }
}

final class Main {
use Loader;
use Singleton;

protected function __construct() {
static::$instance = $this; // before loading classes that can re-enter
$this->load( [ ArticlePostType::class ] ); // instantiates + registers hooks
}
}

Main::get_instance();
```

A registered, REST-enabled post type with no `register_post_type()` call and no `init` hook written by hand. Full walkthrough in [docs/getting-started.md](docs/getting-started.md).

## What's inside
## Usage

- **Registration core** — the spine every consumer boots through:
- `Registrable`, `ConditionallyRegistrable`, `Shareable`, `CLICommand` interfaces
- the `Loader` trait (instantiate a list of classes, register their hooks, cache the shared ones) and the `Container` it stores instances in
- **Twelve `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`, `AbstractAbility`, `AbstractAbilityRegistrar`
- **Asset & render loaders** — `AssetLoader` (scripts/styles/modules + `*.asset.php` manifests), `ComponentLoader` and `TemplateLoader` (resolve components/templates across the child-theme → parent-theme → package hierarchy)
- **`Singleton` trait** — standard `get_instance()` with clone/wakeup guards
- **Utilities & services** (`inc/Utils/`) — context-scoped helpers:
- `Encryptor` — authenticated AES-256-GCM encryption for values stored in the DB
- `Cache` — typed wrapper over the WP object cache, group-namespaced, optional SWR
- `FeatureSelector` + `FeatureSelectorSettingsPage` — a fail-closed feature-flag registry and its admin toggle page
- `Logger` — context-prefixed, `WP_DEBUG`-gated logging
- `Timer` — named request-scoped timers and laps
- `Transients` — prefix-namespaced transient storage

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.

## What's NOT here (intentional)

- **No bootstrap / `Main` class.** The framework gives you the `Loader` trait and the contracts; each consumer writes its own entry class that kicks off the first `load()`. 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.
See [docs/index.md](docs/index.md) for detailed usage instructions.

## Documentation

Start with [docs/index.md](docs/index.md), then:

| Doc | What it covers |
| ----------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [getting-started.md](docs/getting-started.md) | Install, bootstrap a plugin or theme, load a module, and share a service. |
| [architecture.md](docs/architecture.md) | How a class becomes a live hook — the `Registrable` → `Loader` → `Container` flow. Read first. |
| [contracts.md](docs/contracts.md) | The interfaces and traits in detail. |
| [abstracts.md](docs/abstracts.md) | Cookbook for the `Abstract*` base classes. |
| [loaders.md](docs/loaders.md) | `AssetLoader`, `ComponentLoader`, `TemplateLoader` and the theme-override hierarchy. |
| [utilities.md](docs/utilities.md) | `Encryptor`, `Cache`, feature flags, logging, transients, timers, and `Container`. |
| [upgrading.md](docs/upgrading.md) | What changes between releases and what a consumer has to do about it. |
| [troubleshooting.md](docs/troubleshooting.md) | Symptom → cause for the errors and silent no-ops the framework emits. |
| [ai-review-system.md](docs/ai-review-system.md) | How the AI review instructions are authored here and synced into the skeletons. |
| [maintainers.md](docs/maintainers.md) | Development environment, tests, change checklist, and documentation maintenance. |

## Development

```bash
composer install
npm ci
npm run wp-env start
composer lint
composer analyse
npm run lint:js
npm run format
npm run test:php
```

Tests run against real WordPress via [`@wordpress/env`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/). Use `npm run test:php`, which runs PHPUnit inside the wp-env test container; `composer test` only works directly when a host WordPress test suite has been configured. See [docs/maintainers.md](docs/maintainers.md) for the complete workflow.

## Contributing

See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
This repository is maintained by rtCamp. Contributions are welcome and encouraged. See [CONTRIBUTING.md](.github/CONTRIBUTING.md).

## License

Expand Down
Loading
Loading