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.

Maintainers

Package info

github.com/tombroucke/wp-fluent-hooks

pkg:composer/tombroucke/wp-fluent-hooks

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

dev-main 2026-05-01 12:45 UTC

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);