PHPackages                             offsetwp/hook - 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. offsetwp/hook

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

offsetwp/hook
=============

Typed, secure, modern, and object-oriented hook registration for WordPress

1.1.0(6mo ago)026MITPHPPHP &gt;=8.1

Since Aug 4Pushed 6mo agoCompare

[ Source](https://github.com/offsetwp/hook)[ Packagist](https://packagist.org/packages/offsetwp/hook)[ Fund](https://www.buymeacoffee.com/w__jerome)[ Fund](https://ko-fi.com/w__jerome)[ RSS](/packages/offsetwp-hook/feed)WikiDiscussions main Synced today

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

[![OffsetWP Hook](https://raw.githubusercontent.com/offsetwp/offsetwp.github.io/refs/heads/main/public/common/cover/cover-hook-light.png#gh-light-mode-only)](https://raw.githubusercontent.com/offsetwp/offsetwp.github.io/refs/heads/main/public/common/cover/cover-hook-light.png#gh-light-mode-only)[![OffsetWP Hook](https://raw.githubusercontent.com/offsetwp/offsetwp.github.io/refs/heads/main/public/common/cover/cover-hook-dark.png#gh-dark-mode-only)](https://raw.githubusercontent.com/offsetwp/offsetwp.github.io/refs/heads/main/public/common/cover/cover-hook-dark.png#gh-dark-mode-only)

 OffsetWP Hook
===============

[](#----offsetwp-hook)

 Typed, secure, modern, and object-oriented hook registration for WordPress

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

[](#installation)

```
composer require offsetwp/hook
```

Basic usage
-----------

[](#basic-usage)

### Add a basic action

[](#add-a-basic-action)

```
use OffsetWP\Hook\Support\Action;

new class extends Action {
	public string $hook_name = 'init';

	protected function handle() {
		register_post_type(
			'project',
			array(
				'labels' => array(
					'name'          => __( 'Projects', 'offsetwp' ),
					'singular_name' => __( 'Project', 'offsetwp' ),
				),
				'public'      => true,
				'has_archive' => true,
			)
		);
	}
};
```

### Add a basic filter

[](#add-a-basic-filter)

```
use OffsetWP\Hook\Support\Filter;

new class extends Filter {
	public string $hook_name = 'admin_footer_text';

	protected function handle( $text ) {
		return 'Made with love by OffsetWP | ' . $text;
	}
};
```

### Add a basic shortcode

[](#add-a-basic-shortcode)

```
use OffsetWP\Hook\Support\ShortCode;

new class extends ShortCode {
	public string $hook_name = 'my_shortcode';

	protected function handle( array $atts, string $content, string $shortcode_tag ) {
		return 'My shortcode';
	}
};
```

Advanced hook
-------------

[](#advanced-hook)

Hooks all work in the same way: they have a name, a callback function, the order of priority in which they are to be executed, and the number of callback parameters. Only shortcodes have only the hook name and a callback function.

For greater flexibility, it is possible to override some properties without affecting others. Here is an filter with all possible properties:

```
use OffsetWP\Hook\Support\Filter;

new class extends Filter {
	public string $hook_name       = 'admin_footer_text';
	public string $hook_callback   = 'launch'; // default: `handle`
	public int $hook_priority      = 10; // default: 10
	public int $hook_accepted_args = 1; // default: 1

	protected function launch( $text ) {
		return 'Made with love by OffsetWP | ' . $text;
	}
};
```

With more substantial development, it may be necessary for your hooks to use dependencies. All of this is possible, depending on your needs:

```
use OffsetWP\Hook\Support\Filter;

new class extends Filter {
	public string $hook_name = 'admin_footer_text';

	public function __construct( private $myServiceName = 'CustomService' ) {
		return parent::__construct();
	}

	protected function handle( $text ) {
		return $this->myServiceName . ' | ' . $text;
	}
};
```

FAQ
---

[](#faq)

### Why are there only functions for `add_action`, `add_filter`, and `add_shortcode`?

[](#why-are-there-only-functions-for-add_action-add_filter-and-add_shortcode)

The goal of this project is to modernize and simplify development on WordPress. We started with hooks, as they are the most commonly used.

As soon as we identify an elegant way to integrate the following features, they will be added: `do_action` `apply_filters` `remove_action` `remove_filter`

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance66

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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 ~135 days

Total

2

Last Release

196d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f92310287db168bd8da8a7b15d26e9e0849a6c7ab9a30d7fc32497d7e5f4bab8?d=identicon)[w-jerome](/maintainers/w-jerome)

---

Top Contributors

[![w-jerome](https://avatars.githubusercontent.com/u/1685550?v=4)](https://github.com/w-jerome "w-jerome (7 commits)")

---

Tags

wordpressHOOKoffsetwpadd\_actionadd\_filteradd\_shortcode

### Embed Badge

![Health badge](/badges/offsetwp-hook/health.svg)

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

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

439951.1k24](/packages/tormjens-eventy)[php-stubs/wordpress-stubs

WordPress function and class declaration stubs for static analysis.

20416.0M408](/packages/php-stubs-wordpress-stubs)

PHPackages © 2026

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