kaiseki / wp-hook
Register classes with add_filter and add_action hooks
Requires
- php: ^8.2
- kaiseki/config: ^2.0
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- bnf/phpstan-psr-container: ^1.1
- kaiseki/php-coding-standard: ^1.0
- maglnet/composer-require-checker: ^4.0
- php-stubs/wordpress-stubs: ^6.2
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.0
- roave/security-advisories: dev-latest
- roots/wordpress-core-installer: *
- roots/wordpress-no-content: @stable
- szepeviktor/phpstan-wordpress: ^2.0
- thecodingmachine/phpstan-safe-rule: ^1.4
This package is auto-updated.
Last update: 2026-06-02 23:45:32 UTC
README
Register classes with add_filter and add_action hooks.
A hook provider is any object implementing HookProviderInterface — its single
addHooks() method is where you wire WordPress callbacks with add_action() and
add_filter(). You list your provider classes under the hook.provider config key,
and HookProviderRegistry instantiates them through the container and calls addHooks()
on each, so every theme or plugin registers its hooks from one place.
Installation
composer require kaiseki/wp-hook
Requires PHP 8.2 or newer.
Usage
Implement HookProviderInterface and register your WordPress hooks inside addHooks():
use Kaiseki\WordPress\Hook\HookProviderInterface; final class SetupTheme implements HookProviderInterface { public function addHooks(): void { add_action('after_setup_theme', [$this, 'registerMenus']); } public function registerMenus(): void { // register_nav_menus(...); } }
Add the class name to the hook.provider config key:
return [ 'hook' => [ 'provider' => [ SetupTheme::class, ], ], ];
ConfigProvider maps HookProviderRegistry to HookProviderRegistryFactory, which reads
hook.provider from the container, instantiates each provider, and builds the registry.
Calling addHooks() on the registry then fans out to every provider:
use Kaiseki\WordPress\Hook\HookProviderRegistry; /** @var HookProviderRegistry $registry */ $registry = $container->get(HookProviderRegistry::class); $registry->addHooks();
Wire ConfigProvider into your application's config aggregator (e.g. laminas-config-aggregator)
to register the factory.
Development
composer install
composer check # check-deps, cs-check, phpstan, phpunit
License
MIT — see LICENSE.