Download the PHP package level-level/clarkson-hooks without Composer
On this page you can find all versions of the php package level-level/clarkson-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download level-level/clarkson-hooks
More information about level-level/clarkson-hooks
Files in level-level/clarkson-hooks
Package clarkson-hooks
Short Description Solution for 'Just in time' WordPress Hooks.
License MIT
Informations about the package clarkson-hooks
Clarkson Hooks
Solution for 'Just in time' WordPress Hooks.
Clarkson-hooks combines the all
action and composer autoloading to only include the filters you are actually going to use.
Setup
1. Define clarkson-hooks as a dependency.
composer require level-level/clarkson-hooks
It will load automatically.
2. Point Composer towards a directory to find your Hooks
namespace.
3. Define a hook
Example minimal init.php (put this in app/Hooks/init.php
when using path specified in composer above.
Note: the \Clarkson\Hooks\iHook
interface makes sure you correctly define your Hook
object.
For a real live example, check out the init hook in Clarkson Theme.
What happens in the background
- An
apply_filters
ordo_action
is called from WordPress. - Just before the actual hook is triggered, the
do_action('all')
is caught by Clarkson-hooks. - Clarkson-hooks checks for the existence of
\Hooks\{hook-tag}
(Composer handles loading any corresponding file). - The correspondig class gets the static method
register_hooks
called. The actualadd_filter
oradd_action
is done in this file. - WordPress continues as expected.
Tips
Be sure to use the --optimize-autoloader
composer flag on production to have the loading process moving smoothly. Otherwise the class_exists function creates a lot of overhead.
All hooks initialize only once.