PHPackages                             amphibee/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. amphibee/hooks

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

amphibee/hooks
==============

An object-oriented package for the WordPress Plugin API.

12.1kPHP

Since Sep 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ogorzalka/hooks)[ Packagist](https://packagist.org/packages/amphibee/hooks)[ RSS](/packages/amphibee-hooks/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

An object-oriented package for WordPress hooks.
===============================================

[](#an-object-oriented-package-for-wordpress-hooks)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f546e6fa02efa038bbb96ef038893974b9021ab2c73ca9a013461df883a81e8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469676974616c6269746465762f686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitalbitdev/hooks)[![GitHub Tests Action Status](https://camo.githubusercontent.com/cdcca905eabfcdaeb4aecaea20e7965241aac7ccc20c6479d92cc5b1b7dbc96a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6469676974616c6269746465762f686f6f6b732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/digitalbitdev/hooks/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/c0361f0f26ee1c5a9354ae8f61cc7c1b51d0b630bbb564ade40b3135e4ba1159/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469676974616c6269746465762f686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digitalbitdev/hooks)

This package provides an object-oriented API for use with the WordPress [Plugin API](https://codex.wordpress.org/Plugin_API). The package also includes automatic "number of arguments" calculation and chainable callbacks.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require digitalbitdev/hooks
```

Usage
-----

[](#usage)

There is a dedicated class for each type of ["hook"](https://developer.wordpress.org/plugins/hooks/).

### Actions

[](#actions)

To interact with actions, you need to use the `\DigitalBit\Hooks\Action` class.

**Registering actions**:

To register an action, call the `Action::add()` method. This method takes **3 arguments**:

```
use DigitalBit\Hooks\Action;

Action::add($name, $callback, $priority);
```

You do not need to provide the number of parameters that the callback takes. This is automatically resolved using the [Reflection API](https://www.php.net/manual/en/book.reflection.php).

**Chained callbacks**:

It is possible to provide extra callbacks that run **after** your initial callback. For example, you may wish to call one of your application helpers to do something extra.

```
use DigitalBit\Hooks\Action;

Action::add('init', function () {
    // do something here...
})->then([MyPlugin::class, 'checkUserIsAdmin']);
```

The chained callbacks will receive the **return value** and all arguments that the initial callback received.

```
class MyPlugin
{
    public static function checkUserIsAdmin($resultFromInitialCallback, ...$extraArgs)
    {
        // ...
    }
}
```

**Running actions**:

You can fire / run an action using the `Action::do()` method, as well as pass in arguments just like you would with `do_action`.

```
use DigitalBit\Hooks\Action;

Action::do('my_plugin_action', $argument, $another);
```

**Removing actions**:

To remove an action, use the `Action::remove()` method:

```
use DigitalBit\Hooks\Action;

Action::remove('init', $callbackToRemove, $priority);
```

### Filters

[](#filters)

To interact with filters, you need to use the `\DigitalBit\Hooks\Filter` class.

**Registering filters**:

To register a filter, use the `Filter::add()` method:

```
use DigitalBit\Hooks\Filter;

Filter::add('the_title', function ($title) {
    return $title . ' is the title.';
});
```

**Chained callbacks**:

It is possible to provide extra callbacks that run **after** your initial callback. For example, you may wish to call one of your application helpers to do something extra.

```
use DigitalBit\Hooks\Filter;

Filter::add('the_title', function ($title) {
    return $title . ' is the title.';
})->then('strtoupper');
```

The chained callbacks will behave the same way as actions and will receive the **return value** of the initial callback and then any arguments that were passed to the initial callback.

The example above will pass the return value of `$title . ' is the title'` to the `strtoupper` method.

**Applying filters**:

You can apply filters using the `Filter::do()` or `Filter::apply()` methods (`Filter::apply()` is an alias of `Filter::do()`). These behave in the same way as the `Action::do()` method and take the same arguments.

```
use DigitalBit\Hooks\Filter;

$title = Filter::do('the_title', 'Hello, World!');

// or..
$title = Filter::apply('the_title', 'Hello, World!');
```

**Removing filters**:

You can remove filters using the `Filter::remove()` method. This behaves the same as the `Action::remove()` method and both use the same underlying logic.

```
$callback = function () {

};

// logic here...

Filter::remove('the_title', $callback);
```

### Hookable classes

[](#hookable-classes)

This package provides a convenient `Hookable` interface that can be used to register single-use class callbacks.

```
use DigitalBit\Hooks\Contracts\Hookable;

class InitAction implements Hookable
{
    public function execute()
    {
        // ...
    }
}

Action::add('init', InitAction::class);
```

**Receiving hook arguments**:

To receive the arguments passed from the caller, define a constructor on your class and assign them to properties:

```
use DigitalBit\Hooks\Contracts\Hookable;

class TheTitleFilter implements Hookable
{
    private string $title;

    public function __construct(string $title)
    {
        $this->title = $title;
    }

    public function execute()
    {
        if ($this->title !== 'My First Post') {
            return $this->title;
        }

        return "{$this->title} is Amazing!";
    }
}

Filter::add('the_title', TheTitleFilter::class);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ryan Chandler](https://github.com/ryangjchandler)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8435080f3e74b629258f291a62cb72aa9d63ee44d74e588f594dc6378c328fa2?d=identicon)[amphibee](/maintainers/amphibee)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[phayes/geophp

GeoPHP is a open-source native PHP library for doing geometry operations. It is written entirely in PHP and can therefore run on shared hosts. It can read and write a wide variety of formats: WKT (including EWKT), WKB (including EWKB), GeoJSON, KML, GPX, GeoRSS). It works with all Simple-Feature geometries (Point, LineString, Polygon, GeometryCollection etc.) and can be used to get centroids, bounding-boxes, area, and a wide variety of other useful information.

87510.1M20](/packages/phayes-geophp)[jenssegers/optimus

Id obfuscation based on Knuth's integer hash method

1.3k4.8M27](/packages/jenssegers-optimus)[workos/workos-php

WorkOS PHP Library

392.4M5](/packages/workos-workos-php)[php-tui/term

comprehensive low level terminal control

45757.7k1](/packages/php-tui-term)[rkr/wildcards

A simple wildcard matcher

1418.3k](/packages/rkr-wildcards)

PHPackages © 2026

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