PHPackages                             pinkcrab/wp-hook-subscriber - 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. [Framework](/categories/framework)
4. /
5. pinkcrab/wp-hook-subscriber

ActiveLibrary[Framework](/categories/framework)

pinkcrab/wp-hook-subscriber
===========================

Creates a single subscriber for a hook, part of the PinkCrab Perique Framework

2.1.0(2mo ago)1271[5 PRs](https://github.com/Pink-Crab/Perique-Hook-Subscriber/pulls)MITPHPPHP &gt;=8.0.0CI passing

Since Jan 27Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Pink-Crab/Perique-Hook-Subscriber)[ Packagist](https://packagist.org/packages/pinkcrab/wp-hook-subscriber)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-wp-hook-subscriber/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (8)Dependencies (26)Versions (19)Used By (0)

[![logo](/.github/assets/Perique-Hook-Sub-Card.jpg "PinkCrab Perique Hook Subscriber")](/.github/assets/Perique-Hook-Sub-Card.jpg)

Perique Hook Subscriber
=======================

[](#perique-hook-subscriber)

Creates a single subscriber for a hook, part of the PinkCrab Plugin Framework

[![Latest Stable Version](https://camo.githubusercontent.com/4b8b3ca0e573c73987dd1be2f24fd779f019e2fefea79e52521a15293c9ca0cd/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d686f6f6b2d737562736372696265722f76)](https://packagist.org/packages/pinkcrab/wp-hook-subscriber) [![Total Downloads](https://camo.githubusercontent.com/3ac47a8752cba7c346b1a8c85abfb7deef67ef7306c3a07e1a2f8d2b457e52ef/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d686f6f6b2d737562736372696265722f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/wp-hook-subscriber) [![Latest Unstable Version](https://camo.githubusercontent.com/a734b188296b83189665cf36d9b9be3911c94a155e68bddaa8a20136cdb7699a/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d686f6f6b2d737562736372696265722f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/wp-hook-subscriber) [![License](https://camo.githubusercontent.com/4afa4ad700cab8fd6481f5ad43078fbec1eafbce05bee1e625430432a9db85e4/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d686f6f6b2d737562736372696265722f6c6963656e7365)](https://packagist.org/packages/pinkcrab/wp-hook-subscriber) [![PHP Version Require](https://camo.githubusercontent.com/32c26778f06933670929daf2aa82ce3d71aceb1250e9bb59bac903d06ffbfaa4/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f77702d686f6f6b2d737562736372696265722f726571756972652f706870)](https://packagist.org/packages/pinkcrab/wp-hook-subscriber)[![GitHub contributors](https://camo.githubusercontent.com/1ef6d0884794aaca5da00f07456643c94ed8540f85942969ffe3814850fa9c16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175652d486f6f6b2d537562736372696265723f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/1ef6d0884794aaca5da00f07456643c94ed8540f85942969ffe3814850fa9c16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f506572697175652d486f6f6b2d537562736372696265723f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/42a2a96b51432d5629a65a560f012869385dd9b18f9352d37597233543def729/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175652d486f6f6b2d53756273637269626572)](https://camo.githubusercontent.com/42a2a96b51432d5629a65a560f012869385dd9b18f9352d37597233543def729/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f506572697175652d486f6f6b2d53756273637269626572)

[![WP6.6 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_6.yaml)[![WP6.7 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_7.yaml)[![WP6.8 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_8.yaml)[![WP6.9 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/Perique-Hook-Subscriber/actions/workflows/WP_6_9.yaml)

[![codecov](https://camo.githubusercontent.com/7a883818a54a48ca33cf29360b481357d40a55e677e46f864667fe39b093a177/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f506572697175652d486f6f6b2d537562736372696265722f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d45594d34515832435139)](https://codecov.io/gh/Pink-Crab/Perique-Hook-Subscriber)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ec17e7b2353b9eadb1d2a1ac45c97e46383af70d7157e51599fcda5b92194acd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f506572697175652d486f6f6b2d537562736372696265722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/Perique-Hook-Subscriber/?branch=master)[![Maintainability](https://camo.githubusercontent.com/fa09de0c7f3c99102489d3694924359b62a763d377e5dff18e6382ebcbf2620b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f38616331386262303436373366346130646661342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Pink-Crab/Perique-Hook-Subscriber/maintainability)

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

[](#requirements)

Requires PinkCrab Perique Framework V2.1.\*

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

[](#installation)

```
$ composer require pinkcrab/wp-hook-subscriber
```

This module allows for the creation of single Hook Subscriptions for creating an interface with WordPress. Under the hood it still uses the same registration process, the PinkCrab framework is built on, but gives a clean abstraction for single calls.

Each class which extends the provided base class, will have its hook added to the loader on either the defined action or differed. Allowing full use of the DI container.

Due to the way the Loader registers hook calls, classes are instanced on the init hook. Which can be problematic for WooCommerce and other extendable plugins, where some globals are populated later. The Hook\_Subscriber allows for late construction, so your callback will be created in the global scope at that time.

### None Deferred Subscriber

[](#none-deferred-subscriber)

```
class On_Single_Hook extends Abstract_Hook_Subscription {

   /**
    * The hook to register the subscriber
    * @var string
    */
   protected ?string $hook = 'some_hook';

   /**
       * Some service
       * @param My_Service
       */
      protected $my_service;

   public function __construct( My_Service $my_service ) {
      $this->my_service = $my_service;
   }

   /**
    * Callback
    * @param mixed ...$args
    */
   public function execute( ...$args ): void {
      // Args are accessed in the order they are passed.
      // do_action('foo', 'first','second','third',.....);
      //$args[0] = first, $args[1] = second, $args[2] = third, .....

      if ( $args[0] === 'something' ) {
         $this->my_service->do_something( $args[1] );
      }
   }
}

// Would be called by
do_action('some_hook', 'something', ['some','data','to do','something']);
```

### Deferred Subscriber

[](#deferred-subscriber)

```
class Deferred_Hook extends Abstract_Hook_Subscription {

   /**
    * The hook to register the subscriber
    * @var string
    */
   protected ?string $hook = 'some_hook';

   /**
    * Deferred hook to call
    *
    * @var string|null
    */
   protected ?string $deferred_hook = 'some_global_populated';

   /**
    * Our global data
    * @param Some_Global|null
    */
   protected $some_global;

   public function __construct() {
      global $some_global;
      $this->some_global = $some_global;
   }

   /**
    * Callback
    * @param mixed ...$args
    */
   public function execute( ...$args ): void {
      // Depends on a global which is set later than init.
      if ( $args[0] === 'something' && ! empty( $this->some_global ) ) {
         do_something( $this->some_global->some_property, $args[1] );
      }
   }
}
```

> Somewhere in another plugin or wp-core $some\_global is populated, we can then hook in anytime from when thats created and our hook is actually called.

```
function acme_plugin_function(){
    global $some_global; // Currently empty/null
    $some_global = new Some_Global();

    do_action('some_global_populated', ['some', 'data']);
}
```

> When some\_global\_populated is fired, a new instance of Deferred\_Hook is created and the callback is registered. This gives us access to Some\_Global no matter whenever some\_global\_populated(). We end up creating 2 instances of our deferred hooks, once on init to register the first call, then again on our deferred hook, for the actual hook call.

Previous Versions
-----------------

[](#previous-versions)

- For Perique V1.0.\* use Version 1.0.\*
- For Perique V0.4.\* use Version 0.2.2
- For Perique V0.3.\* use Version 0.2.1

Changelog
---------

[](#changelog)

- 2.1.0 - Bump support to Perique 2.1.\*, update dev dependencies, align configs and workflows.
- 2.0.1 - Updates dev dependencies
- 2.0.0 - Drops support for PHP 7.2 &amp; 7.3 and adds support for Perique V2.0.\*
- 1.0.1 - Drops support for PHP 7.1, adds PHP8 support, updates all dependencies and adds 3rd party quality checks (Scrutinizer &amp; CodeClimate)
- 1.0.0 - Now supports Perique and its move from Registerable to Hookable interface naming.
- **---- Core renamed from PinkCrab Plugin Framework to Perique ----**
- 0.2.2 Updated tests and code to reflect changes in Framework 0.4.\*
- 0.2.1 Added in a extra tests and coverage reports.
- 0.2.0 - Moved from the initial Event\_Hook naming and made a few minor changes to how deferred hooks are added, using DI to recreate an new instance, over resetting state.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance85

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% 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 ~272 days

Recently: every ~442 days

Total

8

Last Release

78d ago

Major Versions

0.2.2 → 1.0.02021-06-12

1.0.1 → 2.0.02023-04-03

PHP version history (4 changes)0.2.0PHP &gt;=7.1.0

1.0.1PHP &gt;=7.2.0

2.0.0PHP &gt;=7.4.0

2.1.0PHP &gt;=8.0.0

### Community

Maintainers

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

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (61 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-wp-hook-subscriber/health.svg)

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M297](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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