PHPackages                             typisttech/wp-contained-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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. typisttech/wp-contained-hook

AbandonedArchivedLibrary[PSR &amp; Standards](/categories/psr-standards)

typisttech/wp-contained-hook
============================

Using PSR-11 container implementation in WordPress plugins, themes and packages during WordPress action/filter callbacks.

0.3.1(6y ago)2926.2k4[1 issues](https://github.com/typisttech/wp-contained-hook/issues)[3 PRs](https://github.com/typisttech/wp-contained-hook/pulls)3MITPHPPHP ^7.2

Since Apr 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/typisttech/wp-contained-hook)[ Packagist](https://packagist.org/packages/typisttech/wp-contained-hook)[ Docs](https://typist.tech/projects/wp-contained-hook)[ RSS](/packages/typisttech-wp-contained-hook/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (9)Used By (3)

WP Contained Hook
=================

[](#wp-contained-hook)

[![Packagist](https://camo.githubusercontent.com/c80d800bf24de7afa2a1c9f056bdc2e5635c77d871a2ae4acc3b9d9f1063ef8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747970697374746563682f77702d636f6e7461696e65642d686f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/typisttech/wp-contained-hook)[![Packagist](https://camo.githubusercontent.com/a5aff5a930ac9538d3ff0144209aa11bca92c7af760bcf67756efdf3cf22d300/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f747970697374746563682f77702d636f6e7461696e65642d686f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/typisttech/wp-contained-hook)[![PHP from Packagist](https://camo.githubusercontent.com/40a22b92d9c6629b4a1d31832b198c9e72f0948da30e1cd4567600a4cf671579/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f547970697374546563682f77702d636f6e7461696e65642d686f6f6b3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/40a22b92d9c6629b4a1d31832b198c9e72f0948da30e1cd4567600a4cf671579/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f547970697374546563682f77702d636f6e7461696e65642d686f6f6b3f7374796c653d666c61742d737175617265)[![CircleCI](https://camo.githubusercontent.com/cbced0dc8e356c90d5d25eea62ecbe147a9eb44717b2138b4f1889d092806b0f/68747470733a2f2f636972636c6563692e636f6d2f67682f547970697374546563682f77702d636f6e7461696e65642d686f6f6b2e7376673f7374796c653d737667)](https://circleci.com/gh/TypistTech/wp-contained-hook)[![codecov](https://camo.githubusercontent.com/c93ca031ef1f8926da531bf7af7ade0a36ea0cab4b68c99f5ef197305a5afedf/68747470733a2f2f636f6465636f762e696f2f67682f547970697374546563682f77702d636f6e7461696e65642d686f6f6b2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/TypistTech/wp-contained-hook)[![GitHub](https://camo.githubusercontent.com/89b0371f906c116ea460357915aadc172d859e3b9d1aa3191afcbed790935f18/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f547970697374546563682f77702d636f6e7461696e65642d686f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://github.com/TypistTech/wp-contained-hook/blob/master/LICENSE.md)[![GitHub Sponsor](https://camo.githubusercontent.com/9c923c0024fc20fbd1ea153035ab2b5bb25cf1423c5aa07c35fd3e16b227a307/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d4769744875622d6561346161613f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/sponsors/TangRufus)[![Sponsor via PayPal](https://camo.githubusercontent.com/117a21252fdae389ecc103138cd11218cd7587caf3901b042dfe9dbe3690294e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d50617950616c2d626c75652e7376673f7374796c653d666c61742d737175617265266c6f676f3d70617970616c)](https://typist.tech/donate/wp-contained-hook/)[![Hire Typist Tech](https://camo.githubusercontent.com/8dd68fe769812bdfb1c34fd397ff5e022170342b1d3a47c53055c566ffe8489d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f486972652d547970697374253230546563682d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://typist.tech/contact/)[![Twitter Follow @TangRufus](https://camo.githubusercontent.com/a4aa54a559719fc76a4677ca1d7ec33443d14423085acb58d268fe77f09c61ce/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f54616e6752756675733f7374796c653d666c61742d73717561726526636f6c6f723d316461316632266c6f676f3d74776974746572)](https://twitter.com/tangrufus)

- [Goals](#goals)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
    - [TypistTech\\WPContainedHook\\Loader](#typisttech%5Cwpcontainedhook%5Cloader)
        - [Loader Constructor](#loader-constructor)
        - [Loader::add(HookInterface ...$hooks)](#loaderaddhookinterface-hooks)
        - [Loader::run()](#loaderrun)
    - [Hooks: Action and Filter](#hooks-action-and-filter)
        - [AbstractHook Constructor.](#abstracthook-constructor)
- [FAQs](#faqs)
    - [Will you add support for older PHP versions?](#will-you-add-support-for-older-php-versions)
    - [It looks awesome. Where can I find some more goodies like this?](#it-looks-awesome-where-can-i-find-some-more-goodies-like-this)
    - [Where can I give ⭐⭐⭐⭐⭐ reviews?](#where-can-i-give-starstarstarstarstar-reviews)
- [Sponsoring ❤️](#sponsoring-heart)
    - [GitHub Sponsors Matching Fund](#github-sponsors-matching-fund)
    - [Why don't you hire me?](#why-dont-you-hire-me)
    - [Want to help in other way? Want to be a sponsor?](#want-to-help-in-other-way-want-to-be-a-sponsor)
- [Running the Tests](#running-the-tests)
- [Feedback](#feedback)
- [Change log](#change-log)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Goals
-----

[](#goals)

Using [PSR-11 container implementation](https://www.php-fig.org/psr/psr-11/) in WordPress plugins, themes and packages during WordPress action/filter callbacks.

Dependencies are usually lazy loaded(depends on your container implementation), not instantiated until the first time they are used (during WordPress action/filter callbacks).

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

[](#installation)

Installation should be done via composer, details of how to install composer can be found at .

You need a [`psr/container-implementation` package](https://packagist.org/providers/psr/container-implementation) as well. This readme uses `league/container` as an example (any `psr/container-implementation` works similarly).

```
# league/container is an example, any psr/container-implementation package works
$ composer require typisttech/wp-contained-hook league/container
```

Usage
-----

[](#usage)

```
use League\Container\Container;
use TypistTech\WPContainedHook\Hooks\Action;
use TypistTech\WPContainedHook\Hooks\Filter;
use TypistTech\WPContainedHook\Loader;

$container = new Container;

// Configure the container.
// This depends on your `psr/container-implementation`.
$container->add('bar', Bar::class);
$container->add('foo', Foo::class);

// Action.
$action = new Action('bar', 'admin_init', 'doSomething');

// Filter.
$filter = new Filter('foo', 'the_content', 'filterSomething');

// Add to loader.
$loader = new Loader($container);
$loader->add($action, $filter);

// Add to WordPress.
$loader->run();
```

In plain WordPress, the above is similar to:

```
$bar = new Bar();
add_action('admin_init', [$bar, 'doSomething'])

$foo = new Foo();
add_filter('the_content', [$foo, 'filterSomething'])
```

In WordPress plus container, the above is similar to:

```
add_action('admin_init', function ($arg) use ($container): void {
  $bar = $container->get('bar');
  $bar->doSomething($arg);
})

add_filter('the_content', function ($arg) use ($container) {
  $foo = $container->get('foo');
  return $foo->filterSomething($arg);
})
```

API
---

[](#api)

### TypistTech\\WPContainedHook\\Loader

[](#typisttechwpcontainedhookloader)

Register all actions and filters for the plugin/package/theme.

Maintain a list of all hooks that are registered throughout the plugin, and register them with the WordPress API. Call the run function to execute the list of actions and filters.

#### Loader Constructor

[](#loader-constructor)

- @param Psr\\Container\\ContainerInterface $container The container.

Example:

```
$container = new Container;
$loader = new Loader($container);
```

#### Loader::add(HookInterface ...$hooks)

[](#loaderaddhookinterface-hooks)

Add new hooks to the collection to be registered with WordPress.

- @param HookInterface|HookInterface\[\] ...$hooks Hooks to be registered.

Example:

```
// Action.
$action = new Action(SomeClass::class, 'plugin_loaded', 'doSomething');

// Filter.
$filter = new Filter(SomeClass::class, 'the_content', 'filterSomething');

// Add to loader
$loader->add($action, $filter);
```

#### Loader::run()

[](#loaderrun)

Register the hooks to the container and WordPress.

Example:

```
$loader->run();
```

### Hooks: Action and Filter

[](#hooks-action-and-filter)

Holds necessary information for an action or a filter.

Both `Action` and `Filter` are subclasses of `AbstractHook` and implements `HookInterface`.

#### AbstractHook Constructor.

[](#abstracthook-constructor)

- @param string $hook The name of the WordPress hook that is being registered.
- @param string $classIdentifier Identifier of the entry to look for from container.
- @param string $callbackMethod The callback method name.
- @param int|null $priority Optional.The priority at which the function should be fired. Default is 10.
- @param int|null $acceptedArgs Optional. The number of arguments that should be passed to the $callback. Default is 1.

Example:

```
$action = new Action('bar', 'admin_init', 'doSomething', 20, 2);

$filter = new Filter('foo', 'the_content', 'filterSomething', 20, 2);
```

FAQs
----

[](#faqs)

### Will you add support for older PHP versions?

[](#will-you-add-support-for-older-php-versions)

Never! This plugin will only work on [actively supported PHP versions](https://secure.php.net/supported-versions.php).

Don't use it on **end of life** or **security fixes only** PHP versions.

### It looks awesome. Where can I find some more goodies like this?

[](#it-looks-awesome-where-can-i-find-some-more-goodies-like-this)

- Articles on Typist Tech's [blog](https://typist.tech)
- More projects on [Typist Tech's GitHub profile](https://github.com/TypisTTech/)
- More plugins on [TangRufus'](https://profiles.wordpress.org/tangrufus/#content-plugins) wp.org profiles
- Stay tuned on [Typist Tech's newsletter](https://typist.tech/go/newsletter)
- Follow [@TangRufus](https://twitter.com/tangrufus) on Twitter
- Hire [Tang Rufus](https://typist.tech/contact) to build your next awesome site

### Where can I give ⭐⭐⭐⭐⭐ reviews?

[](#where-can-i-give-starstarstarstarstar-reviews)

Thanks! Glad you like it. It's important to let my know somebody is using this project. Since this is not hosted on wordpress.org, please consider:

- tweet something good with mentioning [@TangRufus](https://twitter.com/tangrufus)
- ⭐ star this [Github repo](https://github.com/typisttech/wp-contained-hook)
- 👀 [watch](https://github.com/typisttech/wp-contained-hook/subscription) this Github repo
- write blog posts
- submit [pull requests](https://github.com/typisttech/wp-contained-hook)
- [sponsor](https://github.com/sponsors/TangRufus) Tang Rufus to maintain his open source projects
- hire [Tang Rufus](https://typist.tech/contact) to build your next awesome site

Sponsoring ❤️
-------------

[](#sponsoring-heart)

Love `WP Contained Hook`? Help me maintain it, a [sponsorship here](https://typist.tech/donation/) can help with it.

### GitHub Sponsors Matching Fund

[](#github-sponsors-matching-fund)

Do you know [GitHub is going to match your sponsorship](https://help.github.com/en/github/supporting-the-open-source-community-with-github-sponsors/about-github-sponsors#about-the-github-sponsors-matching-fund)?

[Sponsor now via GitHub](https://github.com/sponsors/TangRufus) to double your greatness.

### Why don't you hire me?

[](#why-dont-you-hire-me)

Ready to take freelance WordPress jobs. Contact me via the contact form [here](https://typist.tech/contact/) or, via email

### Want to help in other way? Want to be a sponsor?

[](#want-to-help-in-other-way-want-to-be-a-sponsor)

Contact: [Tang Rufus](mailto:tangrufus@gmail.com)

Running the Tests
-----------------

[](#running-the-tests)

Run the tests:

```
$ composer test
$ composer style:check
```

Feedback
--------

[](#feedback)

**Please provide feedback!** We want to make this library useful in as many projects as possible. Please submit an [issue](https://github.com/TypistTech/wp-contained-hook/issues/new) and point out what you do and don't like, or fork the project and make suggestions. **No issue is too small.**

Change log
----------

[](#change-log)

Please see [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

[WP Contained Hook](https://github.com/TypistTech/wp-contained-hook) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://twitter.com/Tangrufus), freelance developer for [hire](https://typist.tech/contact/).

Full list of contributors can be found [here](https://github.com/TypistTech/wp-contained-hook/graphs/contributors).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](./LICENSE) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% 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 ~257 days

Total

5

Last Release

2339d ago

PHP version history (3 changes)0.1.0PHP ^7.0

0.2.0PHP ^7.1

0.3.1PHP ^7.2

### Community

Maintainers

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

---

Top Contributors

[![tangrufus](https://avatars.githubusercontent.com/u/2259834?v=4)](https://github.com/tangrufus "tangrufus (119 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")

---

Tags

dependency-injectionpsr-11wordpresswordpress-developmentwordpress-php-librarycontainerwordpressdependencyinjectiondipsr11filterwpHOOKaction

### Embed Badge

![Health badge](/badges/typisttech-wp-contained-hook/health.svg)

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86892.2M397](/packages/league-container)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2859.2k2](/packages/capsule-di)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1323.5k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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