silverassist/wp-plugin-kernel

Shared LoadableInterface + AbstractPlugin bootstrap pattern for Silver Assist WordPress plugins.

Maintainers

Package info

github.com/SilverAssist/wp-plugin-kernel

pkg:composer/silverassist/wp-plugin-kernel

Transparency log

Statistics

Installs: 303

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-12 21:44 UTC

This package is auto-updated.

Last update: 2026-08-12 21:52:03 UTC


README

Shared LoadableInterface + AbstractPlugin bootstrap pattern for Silver Assist WordPress plugins. Generalizes the singleton-plus-priority-ordered- component-loader pattern that contact-form-to-api already implements by hand, and that SILVERASSIST_STANDARDS.md documents as the target for every plugin — so a concrete plugin only has to write get_components(), not re-implement instance()/init()/the loading loop per repo.

Install

composer require silverassist/wp-plugin-kernel

(Runtime dependency, not --dev — this ships classes your plugin's bootstrap actually calls.)

Usage

<?php
namespace SilverAssist\YourPlugin\Core;

use SilverAssist\PluginKernel\AbstractPlugin;
use SilverAssist\YourPlugin\Admin\SettingsPage;
use SilverAssist\YourPlugin\Service\SomeService;

final class Plugin extends AbstractPlugin {
    protected function get_components(): array {
        return [
            SomeService::class,
            SettingsPage::class,
        ];
    }

    protected function init_hooks(): void {
        // Anything that isn't itself a LoadableInterface component —
        // e.g. wp-github-updater initialization.
    }
}
<?php
// your-plugin.php — main plugin file.
add_action( 'plugins_loaded', static function () {
    \SilverAssist\YourPlugin\Core\Plugin::instance()->init();
} );

Each component listed in get_components() implements SilverAssist\PluginKernel\Interfaces\LoadableInterface directly (for a plain component) or extends AbstractPlugin itself (if it needs its own sub-components — uncommon, but the singleton-per-subclass design supports it).

Testing

SilverAssist\PluginKernel\Testing\TestCase is a thin WP_UnitTestCase base — see its own class docblock for the two non-obvious rules every subclass needs (the deprecated $this->factory trap, and why CREATE TABLE must go in wpSetUpBeforeClass()).

What's deliberately NOT here

  • Coding style / PHPCS / PHPStan — see silverassist/wp-coding-standards.
  • An Activator base class — activation/deactivation logic (creating tables, setting default options) is genuinely plugin-specific enough that a shared base class would have little real behavior to share. Revisit only if a real migration reveals actual duplicated logic worth extracting.

See also

  • AGENTS.md — instructions for AI coding agents working in this repo, including which plugins in the standardization effort are and aren't migration targets for this package.