PHPackages                             lotharthesavior/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lotharthesavior/hook

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

lotharthesavior/hook
====================

The Hook System for PHP Apps

0.0.1(2y ago)02242GPL-3.0PHPPHP ^8.0|^8.1|^8.2

Since Feb 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/lotharthesavior/hook)[ Packagist](https://packagist.org/packages/lotharthesavior/hook)[ Docs](http://github.com/lotharthesavior/hook/)[ RSS](/packages/lotharthesavior-hook/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (2)

Hook
====

[](#hook)

Hook is a hook system for PHP projects. This project is a fork of a fork of a fork, from a long time ago, and now got revived for posterity.

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

[](#installation)

```
composer require lotharthesavior/hook
```

Context
-------

[](#context)

Hooks are a way for one piece of code to interact/modify another piece of code. They are a way for a piece of code to be executed at a certain point in an application. This is a very powerful concept and is used in many applications, including WordPress, to allow developers to modify the behavior of the application without modifying the core code.

Customization points that use hooks are often called "actions" and "filters". An action is a point in the code where something happens, and a filter is a point in the code where something is modified. For example, in WordPress, the `wp_head` action is a point in the code where the `` section of the HTML is output, and the `the_content` filter is a point in the code where the content of a post is modified before it is output.

This class is a rewritten of a fork of the original [PHP Hooks](https://github.com/bainternet/PHP-Hooks/) which is a fork of the original PHP Hooks by John Kolbert. The original class was designed to be used in WordPress plugins and themes, but this class can be used in any PHP project.

Usage
-----

[](#usage)

### Filters

[](#filters)

> Filters are functions that an application passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or writing it to the output buffer - a terminal or a browser). As an example, most input and output in WordPress passes through at least one filter. Filter hooks is a great way to allow other developers to modify or extend the default behavior of any code.

This registers a filter:

```
