PHPackages                             nickjbedford/hooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nickjbedford/hooks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nickjbedford/hooks
==================

Hooks is a small library that provided hookable actions and filters, similar to WordPress. This can be used in any PHP 8.0+ project.

1.0.5(3mo ago)176MITPHPPHP &gt;=8.1

Since May 4Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/nickjbedford/hooks)[ Packagist](https://packagist.org/packages/nickjbedford/hooks)[ Docs](https://github.com/nickjbedford/hooks)[ RSS](/packages/nickjbedford-hooks/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (8)Used By (0)

YetAnother\\Hook
================

[](#yetanotherhook)

Hooks is a small library that provided hookable actions and filters, similar to WordPress. This can be used in any PHP 7.4+ project and is a simple way of implementing plugin capabilities in your applications by exposing hookable actions and filters to plugin-code.

The `Hook` class provides a simple interface to registering functions to call under specific hook names, sorted by priority. A hook's list of functions can then be executed with optional parameters, or used as an accumulator for an initial value.

While the `Hook` class itself can be used to create, register and execute hooks, you can also use the global `hook_*` functions to shortcut these operations.

---

### Menu Example

[](#menu-example)

A menu might include a default list of items, then this list may be passed to a filter hook to allow plugins to modify or append to the list.

#### Application Usage

[](#application-usage)

```
$menu = [
    'Plugins' => [
        new MenuItem('Plugin Manager', '/plugins/index')
    ]
];
$menuItems = hook_filter('main_menu', $menu);

// Add menu items to UI...
```

#### Plugin Usage

[](#plugin-usage)

A plugin can then modify the list by receiving it and adding its own items through a callback added to the same hook.

```
hook_add('main_menu', function(array $menu)
{
    $menu['Plugins'][] = new MenuItem('My Plugin', '/my-plugin/');
    return $menu;
});
```

---

Executing Actions with Hooks
----------------------------

[](#executing-actions-with-hooks)

To create, add a function to a hook then execute it, use the following alternatives:

```
$hook = \YetAnother\Hook::get('do_stuff');
$hook->add(function($param)
{
    print($param);
});
$hook->run('Hello, world!');

// "Hello, world!" is printed
```

```
hook_add('do_stuff', fn($param) => print($param));
hook_run('do_stuff', 'Hello, world!');
```

Filtering with Hooks
--------------------

[](#filtering-with-hooks)

By registering callbacks on a hook used as a filter, you can receive input and pass results to the next function in the filter.

```
hook_add('accumulate', fn($initial, $parameter) => $initial + $parameter);
hook_add('accumulate', fn($initial, $parameter) => $initial * $parameter);

$result = hook_filter('accumulate', 5, 7);

// $result = 54 ((5 + 7) * 7)
```

```
hook_add('menu', function(array $menu)
{
    $menu[] = 'World';
    return $menu;
});

$menu = hook_filter('menu', [ 'Hello' ]);

// $menu = [ 'Hello', 'World' ]
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance82

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~299 days

Recently: every ~215 days

Total

7

Last Release

94d ago

Major Versions

0.1.0 → 1.0.02023-11-23

PHP version history (3 changes)0.1.0PHP &gt;=7.4

1.0.0PHP &gt;=8.0

1.0.5PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10795658?v=4)[Nick Bedford](/maintainers/nickjbedford)[@nickjbedford](https://github.com/nickjbedford)

---

Top Contributors

[![nickjbedford](https://avatars.githubusercontent.com/u/10795658?v=4)](https://github.com/nickjbedford "nickjbedford (2 commits)")

---

Tags

hooksfiltersactions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nickjbedford-hooks/health.svg)

```
[![Health](https://phpackages.com/badges/nickjbedford-hooks/health.svg)](https://phpackages.com/packages/nickjbedford-hooks)
```

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

439951.1k24](/packages/tormjens-eventy)[bainternet/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

27624.1k6](/packages/bainternet-php-hooks)[voku/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

7739.7k3](/packages/voku-php-hooks)[x-wp/di

The dependency injection container for WordPress

314.3k14](/packages/x-wp-di)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
