PHPackages                             pop-backbone/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. [API Development](/categories/api)
4. /
5. pop-backbone/php-hooks

ActiveLibrary[API Development](/categories/api)

pop-backbone/php-hooks
======================

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

17.0.1(1mo ago)1369↓100%GPL-2.0-or-laterPHP

Since Jan 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/PoPBackbone/php-hooks)[ Packagist](https://packagist.org/packages/pop-backbone/php-hooks)[ Docs](https://github.com/PoPBackbone/php-hooks)[ RSS](/packages/pop-backbone-php-hooks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (132)Used By (0)

PHP Hooks
=========

[](#php-hooks)

This is a fork of PHP Hooks, adapted for PoP, and adding a couple of updates not merged in the original project.

Install
-------

[](#install)

Via Composer

```
composer require pop-backbone/php-hooks
```

Development
-----------

[](#development)

The source code is hosted on the [GatoGraphQL monorepo](https://github.com/GatoGraphQL/GatoGraphQL), under [`Backbone/packages/php-hooks`](https://github.com/GatoGraphQL/GatoGraphQL/tree/master/layers/Backbone/packages/php-hooks).

PHP-Hooks (Original README)
---------------------------

[](#php-hooks-original-readme)

(Source: )

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 application, 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

48

—

FairBetter than 94% of packages

Maintenance96

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Total

131

Last Release

58d ago

Major Versions

12.2.2 → 13.0.02025-05-23

13.2.0 → 14.0.02025-09-09

14.0.4 → 15.0.02025-09-23

15.3.0 → 16.0.02026-01-12

16.1.0 → 17.0.02026-03-03

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1981996?v=4)[Leonardo Losoviz](/maintainers/leoloso)[@leoloso](https://github.com/leoloso)

---

Top Contributors

[![leoloso](https://avatars.githubusercontent.com/u/1981996?v=4)](https://github.com/leoloso "leoloso (321 commits)")

---

Tags

phpgraphqlhooksfiltersactionsGatoGatoGraphQL

### Embed Badge

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

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

PHPackages © 2026

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