tombroucke / wp-fluent-hooks
There is no license information available for the latest version (dev-main) of this package.
A small utility package that provides a modern, fluent interface for adding WordPress action and filter hooks. Chain methods to build your hooks in a more expressive and readable way.
dev-main
2026-05-01 12:45 UTC
Requires
- php: >=8.0
Requires (Dev)
- brain/monkey: ^2.7
- laravel/pint: ^1.29
- pestphp/pest: ^4.6
- phpstan/phpstan: ^2.1
- szepeviktor/phpstan-wordpress: ^2.0
This package is auto-updated.
Last update: 2026-05-01 12:45:59 UTC
README
Filters
Basic usage:
Filter::hook('the_title') ->register(fn ($title) => strtoupper($title));
With priority and argument count:
Filter::hook('save_post') ->args(3) // Default 1 ->priority(11) // Default 10 ->register(function ($postId, $post, $update) { // Do something });
Actions
Action and Filter share the same API and can be used interchangeably.
Action::hook('init') ->register(function () { // Do something });
Aliases
Assign an alias to reference the hook later:
Action::hook('body_class') ->alias('my_custom_body_class') ->register(fn ($classes) => array_merge($classes, ['custom-class']));
Deregistering
Remove a registered hook by its alias:
Action::deregister('my_custom_body_class');
If you didn't define an alias, retrieve the auto-generated one from the registered instance:
$filter = Filter::hook('the_title') ->register(fn ($title) => strtoupper($title)); $alias = $filter->getAlias(); Filter::deregister($alias);