PHPackages                             micropackage/dochooks - 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. micropackage/dochooks

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

micropackage/dochooks
=====================

DocHooks - annotated WordPress hooks

1.1.4(2y ago)3762.4k↓47.1%33GPL-3.0-or-laterPHPPHP &gt;=5.6

Since Jan 7Pushed 2y ago4 watchersCompare

[ Source](https://github.com/micropackage/dochooks)[ Packagist](https://packagist.org/packages/micropackage/dochooks)[ RSS](/packages/micropackage-dochooks/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (10)Used By (3)

DocHooks
========

[](#dochooks)

[![BracketSpace Micropackage](https://camo.githubusercontent.com/7a9f5ff780f859fdebce60d4e11572de05f86c42ef96b77967c24d7ea7d1e04b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f427261636b657453706163652d4d6963726f7061636b6167652d627269676874677265656e)](https://bracketspace.com)[![Latest Stable Version](https://camo.githubusercontent.com/38a41abebc9702c723bf66de58a5ae506690ff0c8cbdfb9e45f09b44e906e8f6/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f646f63686f6f6b732f762f737461626c65)](https://packagist.org/packages/micropackage/dochooks)[![PHP from Packagist](https://camo.githubusercontent.com/70f102c054b9683e17b8603c5d12676790bd8f45145c876a8ed0cd4323cf6dd2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6963726f7061636b6167652f646f63686f6f6b732e737667)](https://packagist.org/packages/micropackage/dochooks)[![Total Downloads](https://camo.githubusercontent.com/1f4c26e5897bb5f6db1469e0005a673debad2f8446856be7e6d3d78028aeacb3/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f646f63686f6f6b732f646f776e6c6f616473)](https://packagist.org/packages/micropackage/dochooks)[![License](https://camo.githubusercontent.com/38b006b33bb357cb8d18982131048570b390d71cd44bbedc0781839accf9f089/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f646f63686f6f6b732f6c6963656e7365)](https://packagist.org/packages/micropackage/dochooks)

 [![Micropackage logo](https://camo.githubusercontent.com/9b9fc4f221b3683db4f9cc63e1ed92220004bbda118206d0a26d5ce6377d4d46/68747470733a2f2f627261636b657473706163652e636f6d2f6578747261732f6d6963726f7061636b6167652f6d6963726f7061636b6167652d736d616c6c2e706e67)](https://camo.githubusercontent.com/9b9fc4f221b3683db4f9cc63e1ed92220004bbda118206d0a26d5ce6377d4d46/68747470733a2f2f627261636b657473706163652e636f6d2f6578747261732f6d6963726f7061636b6167652f6d6963726f7061636b6167652d736d616c6c2e706e67)

🧬 About DocHooks
----------------

[](#-about-dochooks)

The Laravel or Symfony projects are using method annotations for various things. This helps to have the project organized without too much code. WordPress has no implementation of such concept and this package is a remedy.

DocHooks package allows you to do:

```
class Example extends HookAnnotations {

	/**
	 * @action test
	 */
	public function test_action() {}

	/**
	 * @filter test 5
	 */
	public function test_filter( $val, $arg ) {
		return $val;
	}

	/**
	 * @shortcode test
	 */
	public function test_shortcode( $atts, $content ) {
		return 'This is test';
	}

}

$example = new Example();
$example->add_hooks();
```

Instead of old:

```
$example = new Example();

add_action( 'test', [ $example, 'test_action' ] );
add_filter( 'test', [ $example, 'test_filter' ], 5, 2 );
add_shortcode( 'test', [ $example, 'test_shortcode' ] );
```

💾 Installation
--------------

[](#-installation)

```
composer require micropackage/dochooks
```

🕹 Usage
-------

[](#-usage)

### Annotations

[](#annotations)

```
@action
@filter
@shortcode

```

The hook and shortcode name is required while default priority is `10`.

You don't provide the argument count, the class will figure it out. Just use the callback params you want.

### Test if DocHooks are working

[](#test-if-dochooks-are-working)

When OPCache has the `save_comments` and `load_comments` disabled, this package won't work, because the comments are stripped down. [See the fallback solution](#fallback).

```
use Micropackage\DocHooks\Helper;

(bool) Helper::is_enabled();
```

### Using within the class

[](#using-within-the-class)

You can extend the HookAnnotations class:

```
use Micropackage\DocHooks\HookAnnotations;

class Example extends HookAnnotations {

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = new Example();
$example->add_hooks();
```

Or use the Trait:

```
use Micropackage\DocHooks\HookTrait;

class Example {

	use HookTrait;

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = new Example();
$example->add_hooks();
```

### Using as a standalone object

[](#using-as-a-standalone-object)

```
use Micropackage\DocHooks\Helper;

class Example {

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = Helper::hook( new Example() );
```

### Fallback

[](#fallback)

Because the HookAnnotations object stores the called hooks in `_called_doc_hooks` property, you are able to pull them out and parse them into a list of old `add_action`, `add_filter` and `add_shortcode` functions.

For this you'll need a central "repository" of all objects with hooks ie. Runtime class. [See the example of this approach](https://github.com/BracketSpace/Notification/blob/master/src/Cli/DumpHooks.php) in the Notification plugin, which uses the WP CLI to dump all the hooks into separate file.

📦 About the Micropackage project
--------------------------------

[](#-about-the-micropackage-project)

Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.

The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.

Micropackages are maintained by [BracketSpace](https://bracketspace.com).

📖 Changelog
-----------

[](#-changelog)

[See the changelog file](./CHANGELOG.md).

📃 License
---------

[](#-license)

This software is released under MIT license. See the [LICENSE](./LICENSE) file for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~175 days

Total

8

Last Release

1061d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd1fdcaa145bfe7d6d015951da54a856f34988c581ae5a2de4c9df6d3b696ebc?d=identicon)[kubitomakita](/maintainers/kubitomakita)

---

Top Contributors

[![jakubmikita](https://avatars.githubusercontent.com/u/18362490?v=4)](https://github.com/jakubmikita "jakubmikita (24 commits)")[![szaleq](https://avatars.githubusercontent.com/u/25011639?v=4)](https://github.com/szaleq "szaleq (15 commits)")[![BracketSpaceWorker](https://avatars.githubusercontent.com/u/55354984?v=4)](https://github.com/BracketSpaceWorker "BracketSpaceWorker (12 commits)")[![mircobabini](https://avatars.githubusercontent.com/u/636911?v=4)](https://github.com/mircobabini "mircobabini (1 commits)")

---

Tags

annotationsbracketspacecomposer-librarymicropackagewordpress

### Embed Badge

![Health badge](/badges/micropackage-dochooks/health.svg)

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

###  Alternatives

[madewithlove/laravel-nova-uuid-support

Adds uuid and other string identifier support to Laravel Nova

28132.9k](/packages/madewithlove-laravel-nova-uuid-support)[delight-im/ids

Short, obfuscated and efficient IDs for PHP

289.5k1](/packages/delight-im-ids)

PHPackages © 2026

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