PHPackages                             kerryrandolph/wp-hook-annotations - 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. kerryrandolph/wp-hook-annotations

ActiveLibrary

kerryrandolph/wp-hook-annotations
=================================

Use PHP docblock @annotations to register WordPress hooks, filters and shortcodes

0.0.3(6y ago)71.3k[1 PRs](https://github.com/Kerry-Randolph/wp-hook-annotations/pulls)MITPHPPHP &gt;=7.2CI failing

Since Jun 4Pushed 3mo agoCompare

[ Source](https://github.com/Kerry-Randolph/wp-hook-annotations)[ Packagist](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)[ Docs](https://github.com/Kerry-Randolph/wp-hook-annotations)[ RSS](/packages/kerryrandolph-wp-hook-annotations/feed)WikiDiscussions develop Synced 3d ago

READMEChangelogDependencies (9)Versions (5)Used By (0)

Wordpress Hook Annotations
==========================

[](#wordpress-hook-annotations)

Use PHP Docblock `@annotations` to register WordPress hooks, filters and shortcodes.

[![Latest Stable Version](https://camo.githubusercontent.com/9a99edb9aa4c0030b11349b372b8d5c66037ec4674fc810d253af3121e2186bc/68747470733a2f2f706f7365722e707567782e6f72672f6b6572727972616e646f6c70682f77702d686f6f6b2d616e6e6f746174696f6e732f762f737461626c65)](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)[![Total Downloads](https://camo.githubusercontent.com/02925f2e7a1f3a1c352159377efbd2d63578c3720490bbd287b8e50dfd261b9d/68747470733a2f2f706f7365722e707567782e6f72672f6b6572727972616e646f6c70682f77702d686f6f6b2d616e6e6f746174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)[![Latest Unstable Version](https://camo.githubusercontent.com/1dca353184a534f21ac317fda5755723e71f26ad5b138eb713bedd4ddd6c7e53/68747470733a2f2f706f7365722e707567782e6f72672f6b6572727972616e646f6c70682f77702d686f6f6b2d616e6e6f746174696f6e732f762f756e737461626c65)](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)[![License](https://camo.githubusercontent.com/fc381635399d80d11b5c45d506edee6b76a9bb437b4aa65d114eb87fda8e13eb/68747470733a2f2f706f7365722e707567782e6f72672f6b6572727972616e646f6c70682f77702d686f6f6b2d616e6e6f746174696f6e732f6c6963656e7365)](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)[![composer.lock](https://camo.githubusercontent.com/1242821e6f12167b71dbd5e4dc64632336301c97c72d601cafea0315a2a0a264/68747470733a2f2f706f7365722e707567782e6f72672f6b6572727972616e646f6c70682f77702d686f6f6b2d616e6e6f746174696f6e732f636f6d706f7365726c6f636b)](https://packagist.org/packages/kerryrandolph/wp-hook-annotations)

Requirements
------------

[](#requirements)

- PHP 7.2+
- PHP-DI 6

Install
-------

[](#install)

Via Composer

```
$ composer require kerryrandolph/wp-hook-annotations
```

Usage
-----

[](#usage)

Instead of wiring callbacks with boilerplate `add_action()`, `add_filter()`, or `add_shortcode()`, simply add the annotations directly to the callback function's docblock:

```
/**
  * @Action(tag="wp_loaded",priority=10,accepted_args=1)
  */
public function doSomething(){
  // do something
}
```

The following annotations can be used:

```
/**
 * @Action(tag="the_hook_name", priority=1, accepted_args=1)
 * @Filter(tag="the_filter_name", priority=1, accepted_args=1)
 * @Shortcode(tag="the_shortcode_name")
 */
```

- The `priority` and `accepted_args` parameters are optional, and default to 10 and 1 respectively
- Double quotes are required: `tag="double_quoted"`. single quotes will throw an exception

Wire multiple hooks to a single callback function:

```
/**
  * @Filter(tag="some_wp_filter")
  * @Action(tag="some_wp_action")
  * @Filter(tag="another_wp_filter")
  */
public function updateSomeValue(string $value): string {
  return 'updated';
}
```

Once you have added the hook annotations, you need to get the `HookManager` object to process them.

If you are using Dependency Injection, the easiest way is by using the provided `HookAware` trait:

```
class MyWordpressHookClass {
  use HookAware;

  /**
    * @Action(tag="wp_loaded")
    */
  public function foo(){}
}
```

The `HookAware->processHooks` method is triggered automatically by the DI container, and uses reflection to discover the hooks and wire them into Wordpress.

Alternatively, you could get the `HookManager` in the constructor via DI, and manually trigger `processHooks`:

```
__construct( HookManager $hook_manager ) {
  $hook_manager->processHooks( $this );
}
```

License
-------

[](#license)

WP Hook Annotations is released under [the MIT License](LICENSE).

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance54

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Total

3

Last Release

2536d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e2496b3207514c3c923a42c1d63b95eaeb20f6d4f95f771ac01924696cda716?d=identicon)[kerryrandolph](/maintainers/kerryrandolph)

---

Top Contributors

[![Kerry-Randolph](https://avatars.githubusercontent.com/u/51205041?v=4)](https://github.com/Kerry-Randolph "Kerry-Randolph (17 commits)")

---

Tags

phpdocwordpressreflectionannotationsdocblocks

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kerryrandolph-wp-hook-annotations/health.svg)

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

###  Alternatives

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.1k706.8M26](/packages/phpdocumentor-reflection-common)[symfony/type-info

Extracts PHP types information.

19751.9M114](/packages/symfony-type-info)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[10up/elasticpress

Supercharge WordPress with Elasticsearch.

1.3k374.3k6](/packages/10up-elasticpress)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12521.4M109](/packages/phpdocumentor-reflection)[php-di/phpdoc-reader

PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)

7431.6M55](/packages/php-di-phpdoc-reader)

PHPackages © 2026

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