A simple PHP Hooks system for registering hookable events, adding callbacks to registered events, and running callback associated with registered events.
You can use the Hooks class directly or by using some of the helper functions in helper.php
Step 1. Add Hookable Event
// Method 1
Hooks::getInstance()->add_hookable_event('header');
// Method 2
$hooks = Hooks::getInstance();
$hooks->add_hookable_event('header');
Step 2. Add some callbacks to the event
// Method 1
Hooks::getInstance()->add_action('header', 'myFunction'); // Where myFunction is a valid function
Hooks::getInstance()->add_action('header', 'include_css'); // Where include_css is a valid function
// Method 2
$hooks = Hooks::getInstance();
$hooks->add_action('header', 'myFunction'); // Where myFunction is a valid function
$hooks->add_action('header', 'include_css'); // Where include_css is a valid function
Step 3. Run the callbacks associated with the event
// Method 1
Hooks::getInstance()->run_actions('header');
// Method 2
$hooks = Hooks::getInstance();
$hooks->->run_actions('header')
Step 1. Add Hookable Event
add_hookable_event('footer');
Step 2. Add some callbacks to the event
add_action('footer', 'myFunction'); // Where myFunction is a valid function
Step 3. Run the callbacks associated with the event
run_actions('footer');
- Add a way to specify the running order of actions registered to an event
- Maybe tags like: run_after, run_before, run_first, run_last?
- Make a way to call a callback with an array of data. Read: call_user_func_array