path relative to the plugin directory. * * An explicit map, not a name-to-filename convention: the convention would have to guess that * GuardPress_URLhaus lives in class-urlhaus-integration.php and that GuardPress_Threat_Intel_Signatures * does not live in class-threat-intel.php. A map is checked once, here, and cannot mis-derive. */ private static $map = array( 'GuardPress_Baseline' => 'includes/scanner/class-baseline.php', 'GuardPress_Hasher' => 'includes/scanner/class-hasher.php', 'GuardPress_Scan_Runner' => 'includes/scanner/class-scan-runner.php', 'GuardPress_Batch_Scanner' => 'includes/scanner/class-batch-scanner.php', 'GuardPress_Update_Detector' => 'includes/scanner/class-update-detector.php', 'GuardPress_Pattern_Detector' => 'includes/scanner/class-pattern-detector.php', 'GuardPress_Database_Scanner' => 'includes/scanner/class-database-scanner.php', 'GuardPress_Visual_Diff' => 'includes/scanner/class-visual-diff.php', 'GuardPress_Repository_Comparison' => 'includes/scanner/class-repository-comparison.php', 'GuardPress_Threat_Feed' => 'includes/scanner/class-threat-feed.php', 'GuardPress_Extended_Signatures' => 'includes/scanner/class-extended-signatures.php', 'GuardPress_Signatures_Database' => 'includes/scanner/class-signatures-database.php', 'GuardPress_YARA_Signatures' => 'includes/scanner/class-yara-signatures.php', 'GuardPress_Threat_Intel_Signatures' => 'includes/scanner/class-threat-intel-signatures.php', 'GuardPress_MalwareBazaar' => 'includes/scanner/class-malwarebazaar.php', 'GuardPress_URLhaus' => 'includes/scanner/class-urlhaus-integration.php', 'GuardPress_Malware_Scanner' => 'includes/scanner/class-malware-scanner.php', 'GuardPress_False_Positive_Prevention' => 'includes/scanner/class-false-positive-prevention.php', 'GuardPress_Smart_Threat_Feed' => 'includes/scanner/class-smart-threat-feed.php', 'GuardPress_AI_Analyzer' => 'includes/ai/class-ai-analyzer.php', // ACG-149-R41b — THE ADMIN UI, which was also being parsed for every anonymous visitor. // Measured after the scanner was deferred: a front-end page load still pulled in 45 plugin // files / 1.62 MB, and class-admin-menu.php (134 KB) plus class-admin-pro.php (110 KB) were // among the largest. Every hook those three register is admin-only — admin_menu, admin_init, // admin_enqueue_scripts, admin_notices, in_admin_header, wp_ajax_*, admin_post_* and // plugin_action_links_ (the Plugins screen). admin_post_* and wp_ajax_* both run under // wp-admin/, where is_admin() is true, so nothing they register can fire on a page view. // Nothing outside admin/ references these classes (checked); the map entry is the safety net. 'GuardPress_Admin_Menu' => 'admin/class-admin-menu.php', 'GuardPress_Admin_Pro' => 'admin/class-admin-pro.php', 'GuardPress_Admin_Tools' => 'admin/class-admin-tools.php', // ACG-149-R41c — the three biggest FREE-Plus modules, all of them admin-only. Their init() // methods were read line by line before this was done, and between them they register only // admin_menu, admin_init, admin_post_* and wp_ajax_* — every one of which runs under wp-admin. // The loader skips them on a front-end request; these entries are the safety net for any code // path that references the class directly. 'GuardPress_FreePlus_Quarantine' => 'includes/free-plus/quarantine/class-quarantine.php', 'GuardPress_FreePlus_Snapshot' => 'includes/free-plus/snapshot/class-snapshot.php', 'GuardPress_FreePlus_AI_Help' => 'includes/free-plus/ai-help/class-ai-help.php', ); /** Registered once; a second call is a no-op. */ private static $registered = false; public static function init() { if ( self::$registered ) { return; } self::$registered = true; spl_autoload_register( array( __CLASS__, 'load' ) ); } /** * @param string $class Class being resolved by PHP. */ public static function load( $class ) { if ( ! isset( self::$map[ $class ] ) ) { return; // not ours — let any other autoloader answer } // ACG-149-R41f: a bare require_once, exactly as bootstrap.php used to do. An is_readable() // pre-test was here and was WRONG in the dangerous direction: it returns false in setups where // require_once would still have succeeded (some open_basedir and networked-filesystem configs), // and then load() returned silently while the caller went on to use the class — turning what // used to be a working request into "Class not found". Failing the same way the old code failed // is strictly better than failing in a new way. require_once GUARDPRESS_PLUGIN_DIR . self::$map[ $class ]; } /** * Load every mapped class eagerly. Used by bootstrap.php for admin/AJAX/cron/CLI requests, where * the load-time hook registrations listed in this file's header must happen before WordPress * dispatches. Returns the class list so a test can assert the map and the eager path agree. * * @return string[] */ public static function load_all() { foreach ( array_keys( self::$map ) as $class ) { self::load( $class ); } return array_keys( self::$map ); } /** The map, for tests and for the machine check that every target file exists. */ public static function map() { return self::$map; } } }