-
Notifications
You must be signed in to change notification settings - Fork 0
Facades and Helpers
Lukman Nakib edited this page May 30, 2026
·
1 revision
Static entry points to deep services, resolved from the container. The scaffold keeps three — each fronts a service worth a memorable static seam:
| Facade | Use |
|---|---|
Asset |
Register/enqueue + localize scripts and styles (admin-gated). |
Cache |
Transient-backed get/set/remember/flush. |
Config |
Read app/Config/*.php values: Config::get('app.demo.seed_tasks', 5). |
use WPPluginMatrix\Facades\Cache;
$count = Cache::remember('books.count', HOUR_IN_SECONDS, fn () => Book::all() ? count(Book::all()) : 0);Why only three? See
docs/adr/0001-collapse-trivial-facades.md. A Facade exists only where the underlying service is deep enough to earn it — don't add one for a thin wrapper.
One-liner builders in app/Helpers/.
SettingsPage::create('my-settings', 'My Settings')
->addField('api_key', 'API Key', 'text')
->addField('mode', 'Mode', 'select', ['live' => 'Live', 'test' => 'Test'])
->register();Admin notices. storeForLater() flashes a notice on the next admin load (shown once, then cleared).
Notice::success('Saved!');
Notice::error('Something went wrong');
Notice::storeForLater('Demo data seeded', 'success'); // survives a redirect; flashes onceCPT::create('portfolio', 'Portfolio', 'Portfolios')
->supports('title', 'editor', 'thumbnail')
->archive(true)
->restApi(true)
->register();Cron::scheduleDaily('my_cleanup', fn () => /* … */);
Cron::schedule('my_task', 'hourly', fn () => /* … */);
Cron::unschedule('my_task');For activation-scheduled cron, prefer contributing to the
wppm/lifecycle/cron_eventsfilter (see Lifecycle & Migrations) so deactivation cleans it up automatically.
WP Plugin Matrix · GPL-2.0-or-later · source · pages are generated from docs/wiki/ — edit there, not in the wiki UI.
Seams
Tooling