pollora/hook

A modern PHP package for WordPress hook (action/filter) management with callback resolution and reflection caching

Maintainers

Package info

github.com/Pollora/hook

pkg:composer/pollora/hook

Transparency log

Statistics

Installs: 65

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-06-23 10:28 UTC

This package is auto-updated.

Last update: 2026-07-02 14:10:40 UTC


README

A modern PHP package for WordPress hook (action/filter) management with callback resolution and reflection caching.

Installation

composer require pollora/hook

Quick Start

use Pollora\Hook\Action;
use Pollora\Hook\Filter;

$action = new Action;
$filter = new Filter;

// Register action
$action->add('init', function () {
    // runs on WordPress init
});

// Register filter
$filter->add('the_content', function (string $content): string {
    return $content . '<p>Appended!</p>';
});

// Execute action
$action->do('my_custom_action', $arg1, $arg2);

// Apply filter
$filtered = $filter->apply('my_filter', $value);

// Remove hook
$action->remove('init', $callback);

Pollora framework users: When the framework is available, prefer the Laravel facades Pollora\Support\Facades\Action and Pollora\Support\Facades\Filter for full DI container support. A notice is emitted if you use the standalone classes within the framework.

Class-based Callbacks

// Class with method matching hook name (StudlyCase convention)
$action->add('wp_loaded', MyInitializer::class);
// Resolves to [new MyInitializer, 'wpLoaded']

// With dependency injection
$action->setCallbackResolver($myResolver);
$action->add('wp_loaded', MyInitializer::class);
// Resolves via $myResolver->resolve(MyInitializer::class)

Documentation

See docs/hooks.md for full documentation.

Testing

composer test

License

GPL-2.0-or-later