PHPackages                             n5s/wp-hook-kit - 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. n5s/wp-hook-kit

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

n5s/wp-hook-kit
===============

A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.

1.0.0(4mo ago)477[1 PRs](https://github.com/nlemoine/wp-hook-kit/pulls)1MITPHPPHP ^8.2CI passing

Since Dec 23Pushed 4mo agoCompare

[ Source](https://github.com/nlemoine/wp-hook-kit)[ Packagist](https://packagist.org/packages/n5s/wp-hook-kit)[ Docs](https://github.com/n5s/wp-hook-kit)[ RSS](/packages/n5s-wp-hook-kit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (1)

WP Hook Kit
===========

[](#wp-hook-kit)

[![Tests](https://camo.githubusercontent.com/d69d2c35b30ff3e0158d93ccf2eab6d0647a03fbd4b3839b7ef681e066e797f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6c656d6f696e652f77702d686f6f6b2d6b69742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/nlemoine/wp-hook-kit/actions/workflows/tests.yml)[![Coverage](https://camo.githubusercontent.com/15171c0f13bff85a3820852d0a11625df703e5fef71db2974ea55676904a209c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6c656d6f696e652f77702d686f6f6b2d6b6974)](https://codecov.io/gh/nlemoine/wp-hook-kit)[![PHPStan](https://camo.githubusercontent.com/71936661c994bdd70ec588a6771c605f8584906d8054c5d607a3bcc6bd943f3c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d627269676874677265656e)](https://phpstan.org/)

A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.

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

[](#installation)

```
composer require n5s/wp-hook-kit
```

Usage
-----

[](#usage)

```
use n5s\WpHookKit\Hook;

// Basic usage - works even before WordPress is loaded
Hook::addFilter('the_content', fn($content) => $content . 'Footer');
Hook::addAction('init', fn() => register_post_type('book', []));

// Run a callback only once (removes itself after first execution)
Hook::addFilterOnce('the_title', fn($title) => $title . ' - Launch Sale!');
Hook::addActionOnce('wp_footer', fn() => echo '');

// Side effects - run code without modifying the filtered value
Hook::addFilterSideEffect('the_content', function($content) {
    error_log('Content rendered: ' . strlen($content) . ' chars');
});

// Combine both: side effect that runs once
Hook::addFilterSideEffectOnce('template_include', function($template) {
    log_first_template_load($template);
});

// Register same callback on multiple hooks
Hook::addFilters(['the_title', 'the_content'], 'esc_html');
Hook::addActions(['wp_head', 'wp_footer'], fn() => do_something());
```

All methods accept the standard WordPress parameters: `$hook`, `$callback`, `$priority = 10`, `$accepted_args = 1`.

Why?
----

[](#why)

**Early registration**: Register hooks before WordPress fully loads. The library writes directly to `$wp_filter` when `add_filter()` isn't available yet. Unlocks the power of bringing features without the "plugin" way hassle when it's not needed (library, composer autoloaded files, etc.).

**Once variants**: Because sometimes, you might not want your callback to be executed every time a hook is called.

**Side effects**: Runs your callback and returns the original value unchanged. Useful to trigger actions when an actual action isn't available, observe filter behavior, etc.

Acknowledgments
---------------

[](#acknowledgments)

This package is gathering multiple package implementations inside a single library, credits goes to:

- [wecodemore/wordpress-early-hook](https://github.com/wecodemore/wordpress-early-hook) — Early hook registration. The only downside is that it can't safely be used inside a library (because Composer doesn't guarantee autoloaded files order). Plus some minor performance improvements.
- [stevegrunwell/one-time-callbacks](https://github.com/stevegrunwell/one-time-callbacks) — Once variants
- [alleyinteractive/wp-filter-side-effects](https://github.com/alleyinteractive/wp-filter-side-effects) — Side effects

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance74

Regular maintenance activity

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

Unknown

Total

1

Last Release

144d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62f16c9d375343e12eb02b2a3095dc9a02047287b5f12f75ef4c59929fcb2802?d=identicon)[n5s](/maintainers/n5s)

---

Top Contributors

[![nlemoine](https://avatars.githubusercontent.com/u/2526939?v=4)](https://github.com/nlemoine "nlemoine (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

wordpresswordpress-php-librarywordpresshooksfiltersactions

### Embed Badge

![Health badge](/badges/n5s-wp-hook-kit/health.svg)

```
[![Health](https://phpackages.com/badges/n5s-wp-hook-kit/health.svg)](https://phpackages.com/packages/n5s-wp-hook-kit)
```

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/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

27621.3k2](/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

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

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)[millat/laravel-hooks

The WordPress filter, action system in Laravel

5715.1k](/packages/millat-laravel-hooks)

PHPackages © 2026

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