getNumberOfParameters(); $caller_rel_path = function_exists('\NeoLibrary\NeoGlobal\get_caller_rel_path') ? \NeoLibrary\NeoGlobal\get_caller_rel_path() : null; foreach ($args as $hook_name_with_prio) { if (is_int($hook_name_with_prio)) { throw new \InvalidArgumentException("Error: Hook name is an integer. Provide the priority in the hook name (e.g. admin_init:20) and omit the number of function parameters (found using reflection)."); } if (!is_string($hook_name_with_prio)) { throw new \InvalidArgumentException("Error: Hook name is not a string."); } $hook_name = explode(":", $hook_name_with_prio)[0]; $hook_prio = explode(":", $hook_name_with_prio)[1] ?? "10"; if ($hook_prio === "max") { $hook_prio = PHP_INT_MAX; } else { $hook_prio = intval($hook_prio); } $wrapped_callback = function (...$args) use ($use_filter, $hook_name, $caller_rel_path, $callback) { return \NeoLibrary\NeoEntrypoint\suppress_plugin_on_error(function () use ($use_filter, $hook_name, $caller_rel_path, $callback, $args) { performance_checkpoint("hook " . ($use_filter ? "filter" : "action") . " " . $hook_name, caller_rel_path: $caller_rel_path, is_start: true); $value = $callback(...$args); performance_checkpoint("hook " . ($use_filter ? "filter" : "action") . " " . $hook_name, caller_rel_path: $caller_rel_path, is_end: true); return $value; }); }; \NeoLibrary\NeoGlobal\val("neo_global__original_hook_callbacks")[func_id($wrapped_callback)] = $callback; ($use_filter ? "add_filter" : "add_action")($hook_name, $wrapped_callback, $hook_prio, $num_params); } } function performance_checkpoint($message, $caller_rel_path = null, $time = null, $is_start = false, $is_end = false) { static $performance_file = __DIR__ . "/_global--hook-performance-exclude-wporg.php"; static $performance_file_exists = null; $performance_file_exists ??= file_exists($performance_file); if (!$performance_file_exists) { return; } static $performance_file_included = false; if (!$performance_file_included) { (fn () => require_once($performance_file))(); $performance_file_included = true; } \NeoLibrary\NeoGlobal\performance_checkpoint_implementation($message, $caller_rel_path, $time, $is_start, $is_end); }