$hook, 'type' => current_filter() === $hook ? 'action' : 'filter', 'timestamp' => microtime(true), 'caller' => $caller, 'args_count' => func_num_args() - 1, ); self::$hooks_executed[] = $hook_info; // Count executions if (!isset(self::$hook_counts[$hook])) { self::$hook_counts[$hook] = 0; } self::$hook_counts[$hook]++; } /** * Get executed hooks * * @param array $args Query arguments * @return array Hooks */ public static function get_hooks($args = array()) { $defaults = array( 'search' => '', 'limit' => 100, ); $args = wp_parse_args($args, $defaults); $hooks = self::$hooks_executed; // Filter by search if ($args['search']) { $hooks = array_filter($hooks, function($hook) use ($args) { return strpos($hook['hook'], $args['search']) !== false; }); } // Limit results if ($args['limit'] > 0) { $hooks = array_slice($hooks, 0, $args['limit']); } return $hooks; } /** * Get hook counts * * @return array Hook counts */ public static function get_hook_counts() { // Sort by count descending arsort(self::$hook_counts); return self::$hook_counts; } /** * Get hooks called multiple times * * @param int $threshold Minimum count * @return array Hooks */ public static function get_frequent_hooks($threshold = 10) { return array_filter(self::$hook_counts, function($count) use ($threshold) { return $count >= $threshold; }); } /** * Record hooks on shutdown */ public static function record_hooks() { $total_hooks = count(self::$hooks_executed); $unique_hooks = count(self::$hook_counts); // Log summary if (class_exists('WP_Debug_Logger')) { WP_Debug_Logger::debug("Hooks executed", array( 'total' => $total_hooks, 'unique' => $unique_hooks, 'top_5' => array_slice(self::$hook_counts, 0, 5, true), )); } // Store for frontend panel set_transient('wp_debug_hooks_data', array( 'total' => $total_hooks, 'unique' => $unique_hooks, 'hooks' => self::$hooks_executed, 'counts' => self::$hook_counts, ), 3600); } /** * Check if hook was executed * * @param string $hook Hook name * @return bool True if executed */ public static function was_hook_executed($hook) { return isset(self::$hook_counts[$hook]); } /** * Get hook execution time * * @param string $hook Hook name * @return float|null Execution time in seconds */ public static function get_hook_execution_time($hook) { foreach (self::$hooks_executed as $hook_info) { if ($hook_info['hook'] === $hook && isset($hook_info['execution_time'])) { return $hook_info['execution_time']; } } return null; } }