array( 'file' => 'logger.php', 'class' => 'WP_Debug_Logger', 'enabled' => true, ), 'hook_monitor' => array( 'file' => 'hook-monitor.php', 'class' => 'WP_Debug_Hook_Monitor', 'enabled' => true, ), 'template_tracer' => array( 'file' => 'template-tracer.php', 'class' => 'WP_Debug_Template_Tracer', 'enabled' => true, ), 'asset_tracker' => array( 'file' => 'asset-tracker.php', 'class' => 'WP_Debug_Asset_Tracker', 'enabled' => true, ), 'profiler' => array( 'file' => 'profiler.php', 'class' => 'WP_Debug_Profiler', 'enabled' => true, ), 'query_analyzer' => array( 'file' => 'query-analyzer.php', 'class' => 'WP_Debug_Query_Analyzer', 'enabled' => true, ), 'frontend_panel' => array( 'file' => 'frontend-panel.php', 'class' => 'WP_Debug_Frontend_Panel', 'enabled' => true, ), 'cli_commands' => array( 'file' => 'cli-commands.php', 'class' => 'WP_Debug_CLI_Commands', 'enabled' => true, ), ); /** * Initialize autoloader */ public static function init() { // Check if debug is enabled globally $debug_enabled = get_option('wp_debug_enabled', true); if (!$debug_enabled) { return; } // Load each module foreach (self::$modules as $module_name => $module_data) { self::load_module($module_name, $module_data); } } /** * Load a single module * * @param string $module_name Module name * @param array $module_data Module data */ private static function load_module($module_name, $module_data) { // Check if module is enabled $module_enabled = get_option('wp_debug_module_' . $module_name, $module_data['enabled']); if (!$module_enabled) { return; } // Build file path $file_path = WP_DEBUG_PLUGIN_DIR . 'inc/' . $module_data['file']; // Check if file exists if (!file_exists($file_path)) { if (WP_DEBUG) { error_log(sprintf('WP Debug: Module file not found: %s', $file_path)); } return; } // Load the file require_once $file_path; // Initialize the class if it has an init method if (class_exists($module_data['class']) && method_exists($module_data['class'], 'init')) { call_user_func(array($module_data['class'], 'init')); } } /** * Get list of available modules * * @return array List of modules */ public static function get_modules() { return self::$modules; } /** * Enable a module * * @param string $module_name Module name * @return bool True on success */ public static function enable_module($module_name) { if (!isset(self::$modules[$module_name])) { return false; } return update_option('wp_debug_module_' . $module_name, true); } /** * Disable a module * * @param string $module_name Module name * @return bool True on success */ public static function disable_module($module_name) { if (!isset(self::$modules[$module_name])) { return false; } return update_option('wp_debug_module_' . $module_name, false); } }