Skip to content

Instantly share code, notes, and snippets.

@fomigo
Created April 1, 2014 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fomigo/9917152 to your computer and use it in GitHub Desktop.
Save fomigo/9917152 to your computer and use it in GitHub Desktop.
wp: hooks simple implementation
<?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