Created
April 1, 2014 16:00
-
-
Save fomigo/9917152 to your computer and use it in GitHub Desktop.
wp: hooks simple implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$actions = array(); | |
function add_action($hook, $function) { | |
global $actions; | |
if (! isset($actions[$hook])) | |
$actions[$hook] = array(); | |
$actions[$hook][] = $function; | |
} | |
function do_action($hook) { | |
global $actions; | |
if (! isset($actions[$hook])) return; | |
foreach ($actions[$hook] as $function) | |
call_user_func($function); | |
} | |
add_action('my_hook_1', function() { | |
echo 'hello from my_hook_1', PHP_EOL; | |
}); | |
add_action('my_hook_2', function() { | |
echo 'Hello from my_hook_2!', PHP_EOL; | |
}); | |
do_action('my_hook_1'); | |
do_action('my_hook_2'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment