PHPackages                             bainternet/php-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. bainternet/php-hooks

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

bainternet/php-hooks
====================

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

1.0.0(10y ago)27621.3k↓38.3%100[3 PRs](https://github.com/bainternet/PHP-Hooks/pulls)2GPL-3.0PHP

Since Sep 7Pushed 7y ago30 watchersCompare

[ Source](https://github.com/bainternet/PHP-Hooks)[ Packagist](https://packagist.org/packages/bainternet/php-hooks)[ Docs](http://bainternet.github.io/PHP-Hooks/)[ RSS](/packages/bainternet-php-hooks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (2)

PHP-Hooks
=========

[](#php-hooks)

The PHP Hooks Class is a fork of the WordPress filters hook system rolled in to a class to be ported into any php based system

- This class is heavily based on the WordPress plugin API and most (if not all) of the code comes from there.

Head Over to [http://bainternet.github.io/PHP-Hooks/](http://bainternet.github.com/PHP-Hooks/) For more info

---

How to Use?
===========

[](#how-to-use)

Simple, Include the class file in your application bootstrap (setup/load/configuration or whatever you call it) and start hooking your filter and action hooks using the global `$hooks`. Ex:

```
include_once('php-hooks.php');
global $hooks;
$hooks->add_action('header_action','echo_this_in_header');

function echo_this_in_header(){
   echo 'this came from a hooked function';
}
```

then all that is left for you is to call the hooked function when you want anywhere in your aplication, EX:

```
echo '';
global $hooks;
$hooks->do_action('header_action');
echo '';
```

and you output will be:

```
this came from a hooked function
```

Methods
=======

[](#methods)

**ACTIONS:**

**add\_action** Hooks a function on to a specific action.

```
 - @access public
 - @since 0.1
 - @param string $tag The name of the action to which the $function_to_add is hooked.
 - @param callback $function_to_add The name of the function you wish to be called.
 - @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
 - @param int $accepted_args optional. The number of arguments the function accept (default 1).

```

**do\_action** Execute functions hooked on a specific action hook.

```
 - @access public
 - @since 0.1
 - @param string $tag The name of the action to be executed.
 - @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
 - @return null Will return null if $tag does not exist

```

**remove\_action** Removes a function from a specified action hook.

```
 - @access public
 - @since 0.1
 - @param string $tag The action hook to which the function to be removed is hooked.
 - @param callback $function_to_remove The name of the function which should be removed.
 - @param int $priority optional The priority of the function (default: 10).
 - @return boolean Whether the function is removed.

```

**has\_action** Check if any action has been registered for a hook.

```
 -  @access public
 -  @since 0.1
 -  @param string $tag The name of the action hook.
 -  @param callback $function_to_check optional.
 -  @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
  When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
  When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

```

**did\_action** Retrieve the number of times an action is fired.

```
 -  @access public
 -  @since 0.1
 -  @param string $tag The name of the action hook.
 -  @return int The number of times action hook $tag is fired

```

**FILTERS:**

**add\_filter** Hooks a function or method to a specific filter action.

```
 - @access public
 -  @since 0.1
 -  @param string $tag The name of the filter to hook the $function_to_add to.
 -  @param callback $function_to_add The name of the function to be called when the filter is applied.
 -  @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
 -  @param int $accepted_args optional. The number of arguments the function accept (default 1).
 -  @return boolean true

```

**remove\_filter** Removes a function from a specified filter hook.

```
 -  @access public
 -  @since 0.1
 -  @param string $tag The filter hook to which the function to be removed is hooked.
 -  @param callback $function_to_remove The name of the function which should be removed.
 -  @param int $priority optional. The priority of the function (default: 10).
 -  @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
 -  @return boolean Whether the function existed before it was removed.

```

**has\_filter** Check if any filter has been registered for a hook.

```
 -   @access public
 -   @since 0.1
 -   @param string $tag The name of the filter hook.
 -   @param callback $function_to_check optional.
 -   @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
   When checking a specific function, the priority of that hook is  returned, or false if the function is not attached.
   When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

```

**apply\_filters** Call the functions added to a filter hook.

```
 -  @access public
 -  @since 0.1
 -  @param string $tag The name of the filter hook.
 -  @param mixed $value The value on which the filters hooked to $tag are applied on.
 -  @param mixed $var,... Additional variables passed to the functions hooked to $tag.
 -  @return mixed The filtered value after all hooked functions are applied to it.

```

There are a few more methods but these are the main Ones you'll use :).

Download
========

[](#download)

You can download this project in either [zip](https://github.com/bainternet/PHP-Hooks/zipball/master) or [tar](https://github.com/bainternet/PHP-Hooks/tarball/master) formats

You can also clone the project with Git by running:

```
$ git clone git://github.com/bainternet/PHP-Hooks.git

```

License
=======

[](#license)

Since this class is derived from the WordPress Plugin API so are the license and they are GPL

[![Analytics](https://camo.githubusercontent.com/b3d363e4204a21f66e0fbc1378b49dd087f7a3ee6a7c33cdd60c92568f92a8dd/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d35303537333133352d352f5048502d486f6f6b732f6d61696e)](https://github.com/bainternet/PHP-Hooks)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 91.7% 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

Unknown

Total

1

Last Release

3906d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a6ff565efa16143dc0996d43b47893545d384b169684f6f79d2e677989e32eb?d=identicon)[bainternet](/maintainers/bainternet)

---

Top Contributors

[![bainternet](https://avatars.githubusercontent.com/u/660572?v=4)](https://github.com/bainternet "bainternet (11 commits)")[![GaryJones](https://avatars.githubusercontent.com/u/88371?v=4)](https://github.com/GaryJones "GaryJones (1 commits)")

---

Tags

hooksfiltersactions

### Embed Badge

![Health badge](/badges/bainternet-php-hooks/health.svg)

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

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)[voku/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

7637.3k3](/packages/voku-php-hooks)[x-wp/di

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)

PHPackages © 2026

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