public function test_hooks() { add_action('LP_TEST_HOOK', function ($data) { return strtoupper($data); }); $this->assertTrue(has_hook('LP_TEST_HOOK')); $this->assertEqual(do_action('LP_TEST_HOOK', 'abc'), 'ABC'); remove_hook('LP_TEST_HOOK'); $this->assertFalse(has_hook('LP_TEST_HOOK')); }
function apply_hook($tag, $value) { $tag = strtoupper($tag); if ($hooks = has_hook($tag)) { ksort($hooks); $args = func_get_args(); reset($hooks); do { foreach ((array) current($hooks) as $hook) { if (!is_null($hook['function'])) { $args[1] = $value; $value = call_user_func_array($hook['function'], array_slice($args, 1, (int) $hook['args_num'])); } } } while (next($hooks) !== false); } return $value; }