results ) { return $this->results; } // Ensure plugin functions are available (needed by detect callbacks). if ( ! function_exists( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } $this->results = array(); $features = OVKIT_Feature_Registry::instance()->get_all(); foreach ( $features as $key => $f ) { $detection = array( 'detected' => null, // true = issue found, false = not relevant, null = unknown. 'message' => '', // human-readable detection result. 'safe' => true, // is it safe to enable right now? 'savings' => '', // estimated savings (e.g. "~10KB", "1 HTTP request"). ); // Run feature-specific detection if defined. if ( ! empty( $f['detect'] ) && is_callable( $f['detect'] ) ) { try { $detection = array_merge( $detection, call_user_func( $f['detect'] ) ); } catch ( \Throwable $e ) { $detection['message'] = 'Detection failed'; } } $this->results[ $key ] = $detection; } // Cache for 1 hour as transient. set_transient( 'ovkit_scan_results', $this->results, HOUR_IN_SECONDS ); return $this->results; } /** * Get cached scan results (don't re-scan). */ public function get_cached(): array { if ( null !== $this->results ) { return $this->results; } $cached = get_transient( 'ovkit_scan_results' ); if ( is_array( $cached ) ) { $this->results = $cached; return $cached; } return $this->scan(); } /** * Force re-scan (clear cache). */ public function rescan(): array { delete_transient( 'ovkit_scan_results' ); $this->results = null; return $this->scan(); } /** * Get summary stats. */ public function get_summary(): array { $results = $this->get_cached(); $features = OVKIT_Feature_Registry::instance()->get_all(); $issues = 0; $safe_fixes = 0; $active = 0; $risky = 0; foreach ( $features as $key => $f ) { if ( ovkit_is_enabled( $key ) ) { ++$active; } $risk = $f['risk'] ?? 'safe'; $det = $results[ $key ] ?? array(); if ( ! empty( $det['detected'] ) ) { ++$issues; if ( 'safe' === $risk || 'recommended' === $risk ) { ++$safe_fixes; } } if ( ovkit_is_enabled( $key ) && ( 'advanced' === $risk || 'risky' === $risk ) ) { ++$risky; } } return array( 'issues' => $issues, 'safe_fixes' => $safe_fixes, 'active' => $active, 'risky' => $risky, 'total' => count( $features ), ); } }