Download the PHP package lotharthesavior/hook without Composer
On this page you can find all versions of the php package lotharthesavior/hook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lotharthesavior/hook
More information about lotharthesavior/hook
Files in lotharthesavior/hook
Package hook
Short Description The Hook System for PHP Apps
License GPL-3.0
Homepage http://github.com/lotharthesavior/hook/
Informations about the package 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
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 <head>
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 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
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:
Now, anywhere in your application, you can execute that filter:
Actions
Actions are functions that an application executes at specific points during execution, or when specific events occur. Actions are a way to make your application do something at a certain point, without modifying the code. In a sense it is like an event listener, but with a different name.
This registers an action:
Now, anywhere in your application, you can execute that action:
The output will be: <div id="extra_header">this came from a hooked function</div>
Methods
Filters
Actions
Shortcodes
License
Since this class is derived from the WordPress Plugin API so are the license, and they are GPL http://www.gnu.org/licenses/gpl.html
Credits
- Ohad Raz (https://github.com/bainternet)
- David Miles (https://github.com/amereservant/PHP-Hooks)
- Lars Moelleken (https://www.moelleken.org)
- Damien "Mistic" Sorel (https://www.strangeplanet.fr)