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

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

flexpress/component-hooks
=========================

Hook system helper for WordPress

v1.0.0(11y ago)01352PHP

Since Aug 13Pushed 11y ago1 watchersCompare

[ Source](https://github.com/FlexPress/component-hooks)[ Packagist](https://packagist.org/packages/flexpress/component-hooks)[ RSS](/packages/flexpress-component-hooks/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (2)

FlexPress theme component
=========================

[](#flexpress-theme-component)

Install via pimple
------------------

[](#install-via-pimple)

Before we done anything else we need to setup the configs in pimple

```
$pimple['configHookable'] = function() {
  return new Config();
};

$pimple['hooker'] = function ($c) {
  return new Hooker($c['objectStorage'], array(
    $c['configHookable']
  ));
};

```

What we have done here is created two configs, one for the hooker and one for a hookable class, we have then passed in the configHookable to the hooker so it can hook all its hooks up.

Note that that $c\['objectStorage'\] is the SPLObjectStorage class.

Setting up hooks
----------------

[](#setting-up-hooks)

To add hook we must first create a class that uses the HookableTrait, lets make a very basic class that does this:

```
class Config {

  use HookableTrait;

}

```

Simples, all done but we should probably add a hook method, so lets do that now:

```
class Config {

  use HookableTrait;

  /**
   * @type action
   */
  public function adminInit() {
    echo "Hello, this is the admin hook being fired";
  }

}

```

This example adds a hook for the config class and the adminInit function for the action admin\_init, not that the method is in camelcase.

As well as setting up actions you can add filters like this:

```
class Config {

  use HookableTrait;

  /**
   * @type action
   */
  public function adminInit() {
    echo "Hello, this is the admin hook being fired";
  }

  /**
   * @type filter
   */
  public function theTitle($title) {
    return strip_tags($title);
  }

}

```

In this example we have added a filter that strips the tags from the title by hooking into the the\_title filter.

So for filters you simply add this to the docblock above the method:

```
/**
 * @type action
 */

```

and for filters you do the same but change the type to filter:

```
/**
 * @type filter
 */

```

Advanced usage
--------------

[](#advanced-usage)

As well as specifying the type of hook you can also specify the priority like this:

```
/**
 * @type action
 * @priority 10
 */

```

And finally you can also specify the number of paramters you expect like this:

```
/**
 * @type action
 * @priority 10
 * @params 3
 */

```

Which allows you to add both action and filter hooks, speficy the priority as well as the number of params you expect, so nothing is taken away from the add\_action and add\_filter functions.

Public methods - Hooker
-----------------------

[](#public-methods---hooker)

- hookUp() - Loops through all the hookables passed to the hooker and hooks them up.

Public methods - HookableTrait
------------------------------

[](#public-methods---hookabletrait)

- hookUp() - Uses reflection to find all public methods with a valid docblock and hook them up.

Protected methods - HookableTrait
---------------------------------

[](#protected-methods---hookabletrait)

- getMethodAttributes() - Gets all the attibutes of a methods docblock.
- getHookName($methodName, $attributes) - For a given method name and attibutes, gets the hook name. e.g. theContent becomes the\_content
- registerHook($hook\_name, $method\_name, $attributes) - Actuallys registers the hook depending on what type it is.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

4342d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b794650fae4ab8d86e8550fa2e0cd8658323e07a8d78b3e96d0bc373bc88d2a?d=identicon)[timperry](/maintainers/timperry)

### Embed Badge

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

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

PHPackages © 2026

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