';
// CSS to hide other plugin notices inside our page
// This prevents HubSpot, WooCommerce etc. notices from appearing in the middle
?>
get_status_badge( $baseline, $total_issues );
GuardPress_Partial_Header::render( 'AI CyberGuard Security Scanner', '', $status_badge );
// Status banner (v1.0.13): one clear verdict at the top of the dashboard, driven
// by the last Malware + Regular scan results. Additive layer — it only reads data
// already available on this page and degrades gracefully if anything is missing.
$this->render_status_banner( $report, $baseline, $total_issues );
// Notices
$this->render_notices( $notice, $baseline, $changed, $new, $deleted );
// Anchor: scroll target for the banner's malware-scanner button.
echo '';
// Action buttons
GuardPress_Partial_Buttons::render_scanner_actions( $this->nonce_action );
// Threat Feed Status Bar — positioned right after scan buttons for visibility
$this->render_threat_feed_status();
// Help text
GuardPress_Partial_Buttons::render_scanner_help();
// Last scan time (above results so user sees when scan ran). Carries the scroll anchor —
// ACG-149-R36-I: only this first render does, or the id is duplicated.
$this->render_last_scan_time( true );
// Anchor: scroll target for the banner's "Review changes" button.
echo '';
// Summary cards
GuardPress_Partial_Cards::render_scan_summary( $total, $changed, $new, $deleted );
// AI Analysis Section
$this->render_ai_analysis( $report );
// Security Score Section (NEW)
$this->render_security_score( $report, $baseline );
// Threat Level Summary (NEW)
$this->render_threat_summary( $report );
// Details table (Scan Details)
echo '
';
// PRO Features Locked Panel - moved to end (after Security Checklist)
$this->render_pro_features_panel();
// Privacy note
GuardPress_Partial_Header::render_privacy_note();
// Footer
GuardPress_Partial_Header::render_footer();
echo '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $priority_badge and $pro_badge are static HTML built from hard-coded literals above
echo '
';
echo '✨ ' . esc_html__( 'Excellent! Your security configuration is optimal.', 'ai-cyberguard' ) . '';
echo '
';
}
echo '
';
echo '
';
echo '
';
}
/**
* Calculate security score with detailed recommendations
*/
private function calculate_security_score_with_recommendations( $report, $baseline ) {
$score = 100;
$recommendations = array();
// Get settings
$free_settings = class_exists( 'GuardPress_Settings' ) ? GuardPress_Settings::get() : array();
$pro_settings = array();
$is_pro = $this->is_pro_active();
if ( $is_pro && class_exists( 'GuardPress_Pro_Settings' ) ) {
$pro_settings = GuardPress_Pro_Settings::get();
}
// ===== CRITICAL CHECKS =====
// 1. No baseline created
if ( empty( $baseline ) ) {
$score -= 30;
$recommendations[] = array(
'priority' => 'critical',
'icon' => '⚠️',
'title' => __( 'Create Security Baseline', 'ai-cyberguard' ),
'description' => __( 'A baseline is required to detect file changes. Without it, the scanner cannot protect your site.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Create Baseline →', 'ai-cyberguard' ),
'pro' => false,
);
}
// 2. HIGH risk files detected
$high_threats = $this->count_threats_by_level( $report, 'high' );
if ( $high_threats > 0 ) {
$score -= min( 25, $high_threats * 5 );
$recommendations[] = array(
'priority' => 'critical',
'icon' => '🔴',
/* translators: %d is the number of high-risk files detected. */
'title' => sprintf( __( '%d HIGH Risk Files Detected', 'ai-cyberguard' ), $high_threats ),
'description' => __( 'These files contain suspicious patterns. Use AI Analysis to determine if they are malware.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Run AI Analysis →', 'ai-cyberguard' ),
'pro' => false,
);
}
// 2b. Malware scan never run, or long stale.
//
// ACG-149-137 (release readiness). Every other item in this list is a SETTINGS TOGGLE, so a user
// could keep a fully green score for months having never once looked for malware. That is the real
// expectation gap: malware detection is the engine's whole purpose, it is a MANUAL action (the
// scheduled scan is integrity-only — see the note on the Scheduled Scans item), and until now
// nothing in the recommendations ever asked for it. The onboarding text in partials/buttons.php
// does say "New here? Run a Malware Scan first", but that is shown once and only to new installs.
//
// Read through the canonical accessor the status banner already uses, so this item and the banner
// can never disagree about whether a scan exists. (It costs one extra report read on this admin
// render; findings are pruned per call. Acceptable here — this is not a hot path.)
$mal_last = ( class_exists( 'GuardPress_Malware_Scanner' ) && method_exists( 'GuardPress_Malware_Scanner', 'get_last_scan' ) )
? GuardPress_Malware_Scanner::get_last_scan()
: null;
$mal_when = ( is_array( $mal_last ) && ! empty( $mal_last['scan_time'] ) ) ? (int) $mal_last['scan_time'] : 0;
// Deduction deliberately MODEST (-12, and -5 for the firewall item below). The score feeds
// user-visible bands in render(): >=80 Excellent, >=60 Good, >=40 Needs Attention, else
// CRITICAL — in red, the same word this product uses for confirmed malware. A first cut used
// -20/-10, which put a brand-new install at 32 and greeted a user with a perfectly clean site
// with "Security Score 32 — Critical" purely because the PLUGIN was not configured yet. That
// conflates "unconfigured" with "compromised" and is its own false impression. With -12/-5 a
// default fresh install lands at 45 = "Needs Attention": honest and actionable, not alarming.
// Pinned by scenario 1 of the ACG-149-137 harness, so a future tweak cannot silently cross a band.
if ( 0 === $mal_when ) {
$score -= 12;
$recommendations[] = array(
'priority' => 'critical',
'icon' => '🔍',
'title' => __( 'Run Your First Malware Scan', 'ai-cyberguard' ),
'description' => __( 'Your site has never been scanned for malware. The baseline detects future changes, but only a malware scan inspects the files you already have.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Scan Now →', 'ai-cyberguard' ),
'pro' => false,
);
} elseif ( ( time() - $mal_when ) > ( 30 * DAY_IN_SECONDS ) ) {
$score -= 8;
$recommendations[] = array(
'priority' => 'high',
'icon' => '🔍',
/* translators: %s is a human-readable time difference, e.g. "2 months". */
'title' => sprintf( __( 'Last Malware Scan Was %s Ago', 'ai-cyberguard' ), human_time_diff( $mal_when, time() ) ),
'description' => __( 'Malware scans are run manually. Run one now to check the files currently on your site.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Scan Now →', 'ai-cyberguard' ),
'pro' => false,
);
}
// ===== HIGH PRIORITY CHECKS =====
// 3. Scheduled scans disabled
if ( empty( $free_settings['scheduled_enabled'] ) ) {
$score -= 10;
$recommendations[] = array(
'priority' => 'high',
'icon' => '⏰',
'title' => __( 'Enable Scheduled Scans', 'ai-cyberguard' ),
// ACG-149-137/138 (release readiness). This said "Automatic daily scans help detect THREATS
// early", which was false: the scheduled scan was GuardPress_Scan_Runner::run(), pure hash
// comparison against the baseline, with no malware detection anywhere in it.
// ACG-149-138 then made it TRUE rather than just re-worded — the scheduled run now
// malware-scans every file it finds changed or new (see class-cron.php) and can email about
// a confirmed threat. So this text was rewritten a SECOND time: the honest description of
// the old behaviour would now UNDERSELL it. Deliberately says "files that changed", not
// "your site", because a full sweep is still the manual scan's job (item 2b above).
'description' => __( 'Automatic scans alert you when your files change, and check every changed file for malware. Currently disabled.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress_settings' ),
'action_text' => __( 'Enable →', 'ai-cyberguard' ),
'pro' => false,
);
}
// 4. Email notifications disabled
if ( empty( $free_settings['email_enabled'] ) ) {
$score -= 8;
$recommendations[] = array(
'priority' => 'high',
'icon' => '📧',
'title' => __( 'Enable Email Alerts', 'ai-cyberguard' ),
// ACG-149-137/138 (release readiness): said "when security issues are detected" while the
// notifier was file-change shaped end to end and a malware finding could not produce an
// email at all. ACG-149-138 added that path (maybe_send now treats a confirmed malware
// finding as its own reason to send, folds it into the dedupe signature, and lets it bypass
// the rate limit), so the promise is now real and this text states all three cases.
'description' => __( 'Get emailed if malware is found, when your files change, or when plugins need updating.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress_settings' ),
'action_text' => __( 'Enable →', 'ai-cyberguard' ),
'pro' => false,
);
}
// 4b. Firewall is observing but not blocking.
//
// ACG-149-137 (release readiness): the WAF items below are inside `if ( $is_pro )` and read
// $pro_settings['waf_*'], so a FREE-PLUS user whose firewall sits in Monitor mode was never told
// — by this engine — that it blocks nothing. Verified in GuardPress_FreePlus_WAF::guard(): the
// mode decides `$enforce`, and in monitor mode the request is recorded and then CONTINUES.
// Monitor is also the default, so this is the out-of-the-box state.
// The setup wizard already refuses to credit monitor mode as done; this makes the scanner page
// agree with the wizard instead of staying silent. Deliberately says nothing about the 'rules'
// flag, whose effect is not verified here.
if ( ! $is_pro && class_exists( 'GuardPress_FreePlus_WAF' ) ) {
$fp_waf = GuardPress_FreePlus_WAF::settings();
if ( is_array( $fp_waf ) && 'enforce' !== ( $fp_waf['mode'] ?? 'monitor' ) ) {
$score -= 5; // modest, for the band reason documented on the malware-scan item above
$recommendations[] = array(
'priority' => 'high',
'icon' => '🔥',
'title' => __( 'Firewall Is Not Blocking Yet', 'ai-cyberguard' ),
'description' => __( 'The firewall is in Monitor mode: it records suspicious requests but lets them through. Switch to Enforce once the log looks clean.', 'ai-cyberguard' ),
// Slug verified against GuardPress_FreePlus_WAF::register_page() — 'guardpress-fp-waf'.
'action_url' => admin_url( 'admin.php?page=guardpress-fp-waf' ),
'action_text' => __( 'Review & Enforce →', 'ai-cyberguard' ),
'pro' => false,
);
}
}
// 5. MEDIUM risk files
$medium_threats = $this->count_threats_by_level( $report, 'medium' );
if ( $medium_threats > 0 ) {
$score -= min( 10, $medium_threats * 2 );
$recommendations[] = array(
'priority' => 'high',
'icon' => '🟠',
/* translators: %d is the number of medium-risk files needing review. */
'title' => sprintf( __( '%d Medium Risk Files Need Review', 'ai-cyberguard' ), $medium_threats ),
'description' => __( 'These files have some suspicious characteristics. Review them to ensure they are legitimate.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Review Files →', 'ai-cyberguard' ),
'pro' => false,
);
}
// ===== PRO FEATURE CHECKS =====
if ( $is_pro ) {
// 6. WAF disabled
if ( empty( $pro_settings['waf_enabled'] ) ) {
$score -= 15;
$recommendations[] = array(
'priority' => 'high',
'icon' => '🔥',
'title' => __( 'Enable Web Application Firewall (WAF)', 'ai-cyberguard' ),
'description' => __( 'The WAF protects against SQL injection, XSS, and other attacks. Start with Monitor mode to avoid blocking legitimate traffic.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress-waf' ),
'action_text' => __( 'Enable WAF →', 'ai-cyberguard' ),
'pro' => true,
);
} elseif ( ( $pro_settings['waf_mode'] ?? 'monitor' ) === 'monitor' ) {
// WAF in monitor mode - informational
$recommendations[] = array(
'priority' => 'low',
'icon' => 'ℹ️',
'title' => __( 'WAF is in Monitor Mode', 'ai-cyberguard' ),
'description' => __( 'Attacks are being logged but not blocked. Switch to Protect mode once you verify no legitimate traffic is flagged.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress-waf' ),
'action_text' => __( 'Review Logs →', 'ai-cyberguard' ),
'pro' => true,
);
}
// 7. 2FA not enabled
if ( empty( $pro_settings['two_factor_enabled'] ) ) {
$score -= 10;
$recommendations[] = array(
'priority' => 'high',
'icon' => '🔐',
'title' => __( 'Enable Two-Factor Authentication', 'ai-cyberguard' ),
'description' => __( 'Add an extra layer of security to admin accounts. Prevents unauthorized access even if passwords are compromised.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress-login-protection' ),
'action_text' => __( 'Enable 2FA →', 'ai-cyberguard' ),
'pro' => true,
);
}
// 8. Cloud backup not configured
if ( empty( $pro_settings['backup_enabled'] ) || empty( $pro_settings['backup_provider'] ) ) {
$score -= 8;
$recommendations[] = array(
'priority' => 'medium',
'icon' => '☁️',
'title' => __( 'Configure Cloud Backup', 'ai-cyberguard' ),
'description' => __( 'Automatic backups to Google Drive, Dropbox, or S3 ensure you can recover from any attack.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress-backup' ),
'action_text' => __( 'Configure →', 'ai-cyberguard' ),
'pro' => true,
);
}
// 9. Real-time monitoring disabled
if ( empty( $pro_settings['realtime_monitor_enabled'] ) ) {
$score -= 5;
$recommendations[] = array(
'priority' => 'medium',
'icon' => '👁️',
'title' => __( 'Enable Real-Time File Monitoring', 'ai-cyberguard' ),
'description' => __( 'Detect file changes as they happen, not just during scheduled scans.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress_settings' ),
'action_text' => __( 'Enable →', 'ai-cyberguard' ),
'pro' => true,
);
}
// 10. Vulnerability scanner disabled
if ( empty( $pro_settings['vulnerability_scan_enabled'] ) ) {
$recommendations[] = array(
'priority' => 'medium',
'icon' => '🔍',
'title' => __( 'Enable Vulnerability Scanner', 'ai-cyberguard' ),
'description' => __( 'Automatically check your plugins and themes for known security vulnerabilities.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=guardpress_settings' ),
'action_text' => __( 'Enable →', 'ai-cyberguard' ),
'pro' => true,
);
}
}
// ===== MEDIUM PRIORITY CHECKS =====
// 11. Changed files not reviewed
$changed_count = isset( $report['changed'] ) ? (int) $report['changed'] : 0;
if ( $changed_count > 0 && $high_threats === 0 && $medium_threats === 0 ) {
$recommendations[] = array(
'priority' => 'medium',
'icon' => '📝',
/* translators: %d is the number of changed files since the baseline. */
'title' => sprintf( __( '%d Changed Files Since Baseline', 'ai-cyberguard' ), $changed_count ),
'description' => __( 'Review these changes or refresh your baseline if they are from legitimate updates.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Review Changes →', 'ai-cyberguard' ),
'pro' => false,
);
}
// 12. New files detected
$new_count = isset( $report['new'] ) ? (int) $report['new'] : 0;
if ( $new_count > 5 ) {
$recommendations[] = array(
'priority' => 'medium',
'icon' => '📄',
/* translators: %d is the number of new files detected. */
'title' => sprintf( __( '%d New Files Detected', 'ai-cyberguard' ), $new_count ),
'description' => __( 'New files were added since baseline. Verify they are from legitimate sources.', 'ai-cyberguard' ),
'action_url' => admin_url( 'admin.php?page=ai-cyberguard' ),
'action_text' => __( 'Review Files →', 'ai-cyberguard' ),
'pro' => false,
);
}
// Ensure score doesn't go below 0
$score = max( 0, $score );
// Sort recommendations by priority
usort( $recommendations, function( $a, $b ) {
$priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
return $priority_order[ $a['priority'] ] - $priority_order[ $b['priority'] ];
});
return array(
'score' => $score,
'recommendations' => $recommendations,
);
}
/**
* Check if PRO is active AND PRO pages are available
*/
private function is_pro_active() {
// Check license exists and is active
if ( ! class_exists( 'GuardPress_License' ) || ! GuardPress_License::is_pro() ) {
return false;
}
// Also check if PRO Admin is loaded (pages actually exist)
if ( ! class_exists( 'GuardPress_Pro_Admin' ) ) {
return false;
}
return true;
}
/**
* Calculate security score (legacy method for compatibility)
*/
private function calculate_security_score( $report, $baseline ) {
$data = $this->calculate_security_score_with_recommendations( $report, $baseline );
return $data['score'];
}
/**
* Count threats by level from report
*/
private function count_threats_by_level( $report, $level ) {
if ( ! isset( $report['details'] ) || ! is_array( $report['details'] ) ) {
return 0;
}
$count = 0;
foreach ( $report['details'] as $path => $data ) {
$status = isset( $data['status'] ) ? $data['status'] : '';
$threat = GuardPress_Partial_Tables::get_threat_level_static( $path, $status );
if ( $threat['level'] === $level ) {
$count++;
}
}
return $count;
}
/**
* Render Threat Level Summary
* @since 1.0.0
*/
private function render_threat_summary( $report ) {
if ( ! isset( $report['details'] ) || empty( $report['details'] ) ) {
return;
}
$critical = $this->count_threats_by_level( $report, 'critical' );
$high = $this->count_threats_by_level( $report, 'high' );
$medium = $this->count_threats_by_level( $report, 'medium' );
$low = $this->count_threats_by_level( $report, 'low' );
$safe = $this->count_threats_by_level( $report, 'safe' );
// ACG-149-145 (owner, 2026-07-27): LOW no longer opens this panel. The owner's clean site produced
// "1 🟡 LOW · 1 🟢 SAFE" and he was right that it says nothing worth a whole panel — a low-severity
// review item plus a clean file is the normal state of a healthy site, and dedicating a headed box
// to it trains people to ignore the box that matters.
//
// Kept, rather than deleting the panel outright (which is what he first asked for), because on an
// INFECTED site this is the big red summary: it is the only place that shows the CRITICAL count at
// a glance. Checked before choosing: the count is also reachable from the results table
// (partials/tables.php) and the status banner's total_threats, so nothing is unreachable either
// way — but a user with three critical findings should not have to read a table to learn that.
// So: silent unless something real needs attention, loud when it does.
if ( $critical + $high + $medium === 0 ) {
return; // nothing actionable — LOW/SAFE alone is the healthy state, not a report
}
echo '
';
echo '
';
echo '⚡ ';
echo esc_html__( 'Threat Analysis', 'ai-cyberguard' );
// ACG-149-145 (owner, 2026-07-27): the "Powered by Heuristics" badge and the "✓ Skip AI" chips were
// removed from this summary. They are INTERNAL vocabulary — they describe how the plugin decided,
// not anything the reader can act on — and "✓ Skip AI" reads like a clickable control while being
// static text. (The real, clickable "Skip AI" action in the results table is a different thing and
// is untouched.) What is left is the part that carries information: how many files in each bucket.
echo '
';
} elseif ( $medium > 0 && $high === 0 ) {
// Message for MEDIUM only (less urgent)
echo '
';
echo '
';
/* translators: %d is the number of medium-risk files found. */
echo '📋 ' . sprintf( esc_html__( '%d MEDIUM risk files found', 'ai-cyberguard' ), esc_html( $medium ) ) . ' - ';
echo esc_html__( 'These may be false positives. Use AI Analysis to verify, or review manually if the file looks unfamiliar.', 'ai-cyberguard' );
echo '
';
echo '
';
}
echo '
';
}
/**
* Render PRO Features Panel
* @since 1.0.0
*/
private function render_pro_features_panel() {
// Use the new PRO Features partial for integrated UI (Model B)
if ( class_exists( 'GuardPress_Partial_Pro_Features' ) ) {
GuardPress_Partial_Pro_Features::render();
} else {
// Fallback to simple banner if partial not loaded
echo '
';
echo '
';
echo '
';
echo '
🚀 ' . esc_html__( 'Upgrade to AI CyberGuard PRO', 'ai-cyberguard' ) . '
';
echo esc_html__( 'Scan your WordPress database for malicious code injections in wp_options, wp_posts, and user accounts.', 'ai-cyberguard' );
echo '
';
// Check if scan was requested
$db_scan_results = get_transient( 'guardpress_db_scan_results' );
echo '
';
// ACG-120-012 (2026-07-05, Yossi): in-page (no-reload) DB scan restored. The result area is a
// container the AJAX handler swaps in place; the button posts via AJAX and scrolls here on
// completion — no redirect, no flash. A no-JS
';
echo '
';
}
/**
* Render database scan results
*/
/**
* ACG-120-012 (2026-07-05, Yossi): return the DB-scan result markup as a STRING (for the in-page
* AJAX handler ajax_db_scan). Builds a view instance and buffers render_database_scan_results()
* so the AJAX swap shows exactly the same markup as a full page render — including the green
* clean state (with the total_issues int-cast) and the red findings list.
*/
/**
* Return the database-scan result markup as a string (used by the in-page AJAX scan handler),
* so the swapped-in content matches a full page render exactly.
*/
public static function render_database_scan_results_html( $results ) {
$view = new self( 'guardpress_ajax' ); // matches GuardPress_Admin_Menu::$nonce_action
ob_start();
$view->render_database_scan_results( $results );
return (string) ob_get_clean();
}
private function render_database_scan_results( $results ) {
// ACG-120-010 (2026-07-05, Yossi): total_issues can arrive as the STRING "0" (values that
// round-trip through the database or JSON come back as strings). The branches below used
// strict === 0, so "0" !== 0 fell through to the RED "issues found" state on a clean scan.
// Cast once here so every comparison is numeric.
if ( isset( $results['total_issues'] ) ) {
$results['total_issues'] = (int) $results['total_issues'];
}
// GP-REL-008: a scan that could not reach every eligible row is INCOMPLETE
// — show amber, never a green "all clear". Mirrors the file-integrity
// "Check Incomplete" convention (class-dashboard-widget.php). Legacy
// results without the coverage key default to complete (green) so older
// transients degrade safely.
$coverage_complete = ! ( isset( $results['coverage_complete'] ) && false === $results['coverage_complete'] );
// Summary
if ( $results['total_issues'] === 0 && ! $coverage_complete ) {
// Partial coverage, nothing found in what WAS scanned — amber, not green.
$skipped_total = 0;
if ( ! empty( $results['coverage'] ) && is_array( $results['coverage'] ) ) {
foreach ( $results['coverage'] as $tbl ) {
$skipped_total += isset( $tbl['skipped'] ) ? (int) $tbl['skipped'] : 0;
}
}
echo '
' . sprintf(
/* translators: %s is the number of database rows that could not be checked. */
esc_html__( 'No suspicious content was found in the rows that were scanned, but %s rows could not be checked. Re-run the scan to cover the rest.', 'ai-cyberguard' ),
esc_html( number_format_i18n( $skipped_total ) )
) . '
';
} else {
echo '
' . esc_html__( 'No suspicious content was found in the rows that were scanned, but some rows could not be checked. Re-run the scan to cover the rest.', 'ai-cyberguard' ) . '
' . esc_html__( 'No suspicious content found in database!', 'ai-cyberguard' ) . '
';
// ACG-119-003 (Yossi): show WHEN it was last scanned so the clean state is clearly the
// result of a real scan, not an empty placeholder.
if ( ! empty( $results['scanned_at'] ) ) {
echo '
' . sprintf(
/* translators: %s: human-readable time since the last database scan (e.g. "5 minutes"). */
esc_html__( 'Last scanned: %s ago', 'ai-cyberguard' ),
esc_html( human_time_diff( (int) $results['scanned_at'], time() ) )
) . '
';
}
echo '
';
} else {
echo '
';
echo '⚠️ ';
/* translators: %d is the number of suspicious database entries found. */
echo '' . sprintf( esc_html__( 'Found %d entries that match code patterns worth reviewing', 'ai-cyberguard' ), esc_html( $results['total_issues'] ) ) . '';
echo '
' . esc_html__( 'These are patterns that CAN appear in malware but are also common in legitimate content (calculators, page builders, SEO and caching plugins). A match does not mean your site is infected. Review each item below, and if you are unsure, have a developer confirm it before changing anything.', 'ai-cyberguard' ) . '
';
echo '
';
// Help box - What should the user do?
echo '
';
echo '
💡 ' . esc_html__( 'What should you do?', 'ai-cyberguard' ) . '
' . esc_html__( 'Click "Edit" to see the full content. Ask yourself: Do I recognize this? Is it from a plugin I installed?', 'ai-cyberguard' ) . '
';
echo '
';
// Step 3
echo '
';
echo '3';
echo '
';
echo '' . esc_html__( 'When to be concerned', 'ai-cyberguard' ) . '';
echo '
' . esc_html__( 'Be worried if you see: Unfamiliar admin users, random character option names, or encoded content you didn\'t add.', 'ai-cyberguard' ) . '
';
echo '
';
// Step 4
echo '
';
echo '4';
echo '
';
echo '' . esc_html__( 'If you find real malware', 'ai-cyberguard' ) . '';
echo '
' . esc_html__( 'If a developer confirms an entry is genuinely malicious: change all passwords, update all plugins and themes, remove the confirmed entry (ideally with professional help and a backup first), and consider restoring from a known-clean backup.', 'ai-cyberguard' ) . '
';
echo '
';
echo '
'; // grid
// ACG-120-013 (2026-07-05, Yossi): prominent professional-help warning. Editing or
// deleting database rows is IRREVERSIBLE and a wrong change can take the whole site
// down, so anyone who is not a developer must be told to hand this to a professional —
// after a backup — and to copy the finding details (what + where) to pass along.
echo '
';
echo '
⚠️ ' . esc_html__( 'Important before you change anything', 'ai-cyberguard' ) . '
';
echo '
' . esc_html__( 'Editing or deleting entries in the database can break your website and is not reversible. If you are not a developer, do NOT change anything yourself. Have a professional developer perform the fix, and only after taking a full backup of your site and database. When you contact a professional, copy the details of each finding below — the description of what was detected and exactly where it is (the table and the entry name) — and send it to them so they know precisely what to check.', 'ai-cyberguard' ) . '
';
echo '
';
// Common false positives info
echo '
';
echo '
' . esc_html__( 'Common false positives:', 'ai-cyberguard' ) . ' ';
echo esc_html__( 'SEO plugins (Yoast, RankMath), page builders (Elementor, Divi), caching plugins, and security plugins (including AI CyberGuard) may trigger alerts because they store code or patterns in the database.', 'ai-cyberguard' );
echo '
';
echo '⚠️ ' . esc_html__( 'Important:', 'ai-cyberguard' ) . ' ';
echo esc_html__( 'Unfamiliar admin users are a serious red flag. If you don\'t recognize a user, check when they were created and delete immediately if suspicious.', 'ai-cyberguard' );
echo '
';
echo '';
// ACG-149-152 (owner, 2026-07-27): the "Scan Again" button was REMOVED.
// It was a plain form POST, so it gave no feedback at all when clicked — the page just reloaded —
// while the real "Scan Database" button above runs through AJAX with a progress indicator. Two
// buttons for one action, behaving differently, with the worse one placed after the results. The
// owner's call is right: anyone wanting to re-scan clicks "Scan Database" again, which is always
// available and says so ("click to scan or re-scan"). "Clear Results" above is kept — that is a
// different action.
echo '
';
echo esc_html__( 'Compare your WordPress core files against official checksums from WordPress.org to detect modifications.', 'ai-cyberguard' );
echo '
';
// Check if verification was run
$core_results = get_transient( 'guardpress_core_verify_results' );
echo '
';
if ( $core_results ) {
// Show results
if ( class_exists( 'GuardPress_Repository_Comparison' ) ) {
echo GuardPress_Repository_Comparison::render_results_html( $core_results ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- render helper returns pre-built, internally-escaped HTML markup
}
// Clear button
echo '
';
echo '';
echo ' ';
echo '';
echo '
';
} else {
// Show verify button
echo '
';
echo '
' . esc_html__( 'Verify your WordPress core files against official checksums to ensure they haven\'t been tampered with.', 'ai-cyberguard' ) . '
';
echo '';
echo '
';
}
echo '
';
echo '
';
}
/**
* Render notices based on actions
*/
private function render_notices( $notice, $baseline, $changed, $new, $deleted ) {
// Missing baseline warning
if ( empty( $baseline ) ) {
GuardPress_Partial_Notices::render( 'warning',
__( 'No baseline found. Please create a baseline before relying on scan results.', 'ai-cyberguard' )
);
}
// Action notices
$notice_map = array(
'scan_done' => array( 'type' => 'info', 'message' => '' ), // Special handling
'baseline_ok' => array( 'type' => 'success', 'message' => __( 'Baseline created successfully.', 'ai-cyberguard' ) ),
'baseline_created' => array( 'type' => 'success', 'message' => __( 'Baseline created successfully.', 'ai-cyberguard' ) ),
'baseline_refreshed' => array( 'type' => 'success', 'message' => __( 'Baseline refreshed successfully.', 'ai-cyberguard' ) ),
'ignored' => array( 'type' => 'info', 'message' => __( 'File added to ignore list.', 'ai-cyberguard' ) ),
'unignored' => array( 'type' => 'info', 'message' => __( 'File removed from ignore list.', 'ai-cyberguard' ) ),
// FIX R-3 (audit 2026-05-25 round 2): two notices were emitted by
// handlers (L-13, M-4 follow-through) but had no mapping here, so
// the user got the redirect with no visible feedback. Both now
// render correctly.
'ignore_failed' => array( 'type' => 'error', 'message' => __( 'Could not add file to ignore list — path was rejected (outside ABSPATH) or the file no longer exists.', 'ai-cyberguard' ) ),
'unknown_cmd' => array( 'type' => 'warning', 'message' => __( 'Unknown command. The action was not executed.', 'ai-cyberguard' ) ),
'ai_analysis_done' => array( 'type' => 'success', 'message' => __( '🤖 AI analysis complete! See insights below.', 'ai-cyberguard' ) ),
'ai_analysis_error' => array( 'type' => 'error', 'message' => '' ), // Special handling
);
if ( $notice === 'scan_done' ) {
GuardPress_Partial_Notices::render_scan_result( $changed, $new, $deleted );
} elseif ( $notice === 'db_scan_done' ) {
// UX fix (Yosi 2026-07): after a Database scan the only feedback was the
// in-section result box far down the page — and when coverage was partial
// it went amber, so the reassuring green "nothing found" the user remembered
// seemed to vanish. Emit a clear top-of-page verdict that reflects the real
// result (reads the same transient the section box uses). Honest about a
// partial scan without hiding the "no malware found" headline.
$db = get_transient( 'guardpress_db_scan_results' );
if ( is_array( $db ) ) {
$db_issues = isset( $db['total_issues'] ) ? (int) $db['total_issues'] : 0;
$db_complete = ! ( isset( $db['coverage_complete'] ) && false === $db['coverage_complete'] );
if ( $db_issues > 0 ) {
GuardPress_Partial_Notices::render( 'error', sprintf(
/* translators: %s is the number of suspicious database entries found. */
_n(
'Database scan complete — %s suspicious entry found. See the details below.',
'Database scan complete — %s suspicious entries found. See the details below.',
$db_issues,
'ai-cyberguard'
),
esc_html( number_format_i18n( $db_issues ) )
) );
} elseif ( $db_complete ) {
GuardPress_Partial_Notices::render( 'success', __( '✅ Database scan complete — no suspicious content found.', 'ai-cyberguard' ) );
} else {
// ACG-122 note #7 (programmer review): a PARTIAL scan was rendered as 'success' with a green
// ✅ "complete". The text was honest, but users read the colour and the tick first, so the
// headline still said "all good" over rows that were never checked — and the in-section box
// right below already goes amber for the same state, so the page contradicted itself.
// Warning is the honest treatment; the "no malware found" fact is still stated plainly.
GuardPress_Partial_Notices::render( 'warning', __( 'Database scan incomplete — no suspicious content was found in the rows that were checked, but some rows could not be scanned. Re-run the scan to cover them.', 'ai-cyberguard' ) );
}
} else {
GuardPress_Partial_Notices::render( 'info', __( 'Database scan complete.', 'ai-cyberguard' ) );
}
} elseif ( $notice === 'ai_analysis_error' ) {
$error_msg = get_transient( 'guardpress_ai_error' );
if ( $error_msg ) {
delete_transient( 'guardpress_ai_error' );
GuardPress_Partial_Notices::render( 'error', $error_msg );
} else {
GuardPress_Partial_Notices::render( 'error', __( 'AI analysis failed. Please try again.', 'ai-cyberguard' ) );
}
} elseif ( 'baseline_created' === $notice || 'baseline_ok' === $notice || 'baseline_refreshed' === $notice ) {
// ACG-137-B2 (self-review of the v1.0.137 diff, 2026-07-17): RENDER the over-size boundary.
//
// This is the third round of the same bug. finalize_baseline() has returned skipped_large and a
// message since ACG-122, and changelog.txt promised "Baseline now tells you when a file was too
// large to index" — but NOTHING rendered it: the JS (buttons.php) reads response.data only for
// truthiness, prints its own hardcoded "Baseline created! Reloading...", then redirects here,
// where a static "Baseline created successfully." was printed from $notice_map. The string
// "larger than the 50 MB limit" existed in exactly two places: the producer, and the changelog
// claim. Teaching the JS to print response.data.message would NOT have fixed it — the redirect
// discards the payload a moment later.
// So the fact is read from where it now durably lives, written beside the count it qualifies
// (guardpress_baseline_info_v1, see class-batch-scanner.php::finalize_baseline). It survives the
// reload because it is state, not a message in flight.
$gp_bi = get_option( 'guardpress_baseline_info_v1' );
$gp_large = ( is_array( $gp_bi ) && isset( $gp_bi['skipped_large'] ) ) ? (int) $gp_bi['skipped_large'] : 0;
$gp_base = ( 'baseline_refreshed' === $notice )
? __( 'Baseline refreshed successfully.', 'ai-cyberguard' )
: __( 'Baseline created successfully.', 'ai-cyberguard' );
if ( $gp_large > 0 ) {
// Amber, not green: some files are NOT covered by change monitoring. A boundary the user
// cannot see is indistinguishable from a boundary that does not exist — and a green tick
// over it actively misleads.
GuardPress_Partial_Notices::render( 'warning', $gp_base . ' ' . sprintf(
/* translators: %s is the number of files that were larger than the 50 MB limit */
_n(
'%s file was larger than the 50 MB limit, so its contents are not covered by change monitoring. You will still be told if it is added, removed, or crosses that limit.',
'%s files were larger than the 50 MB limit, so their contents are not covered by change monitoring. You will still be told if they are added, removed, or cross that limit.',
$gp_large,
'ai-cyberguard'
),
esc_html( number_format_i18n( $gp_large ) )
) );
} else {
GuardPress_Partial_Notices::render( 'success', $gp_base );
}
} elseif ( isset( $notice_map[ $notice ] ) ) {
GuardPress_Partial_Notices::render( $notice_map[ $notice ]['type'], $notice_map[ $notice ]['message'] );
}
}
/**
* v1.0.13: top-of-dashboard status banner — one clear, colour-coded verdict driven by
* the last Malware scan (threats) and the last Regular scan (file changes vs baseline).
* Severity order: Malware threats (red) > Regular changes (amber) > clean (green) >
* never-scanned (blue). Buttons smooth-scroll to the relevant section on this page.
* Additive + defensive: reads only existing options and never fatals if data is missing.
*/
private function render_status_banner( $report, $baseline, $total_issues ) {
// Last MALWARE scan result (threats). The scanner stores this in file storage
// (binlog-safe), so read it through the canonical, file-storage-aware accessor —
// NOT get_option(), which is only a legacy fallback and is empty on normal installs.
$mal = ( class_exists( 'GuardPress_Malware_Scanner' ) && method_exists( 'GuardPress_Malware_Scanner', 'get_last_scan' ) )
? GuardPress_Malware_Scanner::get_last_scan()
: get_option( 'guardpress_malware_scan_result_v1', array() );
$mal_threats = ( is_array( $mal ) && isset( $mal['summary']['total_threats'] ) ) ? (int) $mal['summary']['total_threats'] : 0;
$mal_time = ( is_array( $mal ) && ! empty( $mal['scan_time'] ) ) ? (int) $mal['scan_time'] : 0;
// RC-114-05: a finished scan with zero threats but incomplete coverage must NOT
// read as "You're protected". coverage_complete defaults to true for older results.
$mal_cov_incomplete = ( is_array( $mal ) && isset( $mal['summary']['coverage_complete'] ) ) ? ! $mal['summary']['coverage_complete'] : false;
$mal_cov_warnings = ( is_array( $mal ) && isset( $mal['summary']['coverage_warnings'] ) ) ? (int) $mal['summary']['coverage_warnings'] : 0;
// ACG-135-004 (review round 3): this banner has its OWN logic and consulted only total_threats +
// coverage_complete — so it still printed a green "You're protected / All clear" over a
// HIGH-RISK review item or a MODIFIED CORE FILE. Fixing is_clean in generate_summary() did not
// reach here; the top-of-page verdict is the first (often only) thing the user reads, so it has
// to honour the same three states. Not every review item goes amber — a site full of legitimate
// premium plugins keeps its green (ACG-103b) — only the two that mean "something real needs you".
$mal_potential = ( is_array( $mal ) && isset( $mal['summary']['potential_items'] ) ) ? (int) $mal['summary']['potential_items'] : 0;
$mal_core_issue = ( is_array( $mal ) && ! empty( $mal['summary']['has_core_integrity_issue'] ) );
// Last REGULAR scan (file-integrity vs baseline).
$reg_changes = (int) $total_issues;
$meta = get_option( 'guardpress_last_scan_meta', array() );
$reg_time = ( is_array( $meta ) && ! empty( $meta['time'] ) ) ? (int) $meta['time'] : 0;
// RC-118-05: a Regular (file-integrity) scan that skipped files (missing/unreadable
// mid-scan) is INCOMPLETE — it must read amber, not a green "All clear".
$reg_incomplete = ( is_array( $meta ) && ! empty( $meta['incomplete'] ) );
$reg_skipped = ( is_array( $meta ) && isset( $meta['skipped'] ) ) ? (int) $meta['skipped'] : 0;
// ACG-137-B2 (self-review round 2): the over-cap count is a SEPARATE fact from "could not be read",
// and it needs a reader here or it is just another number nobody ever sees. It never drives the
// banner's STATE — a >50 MB backup is a known, permanent boundary, not a failure, and making it
// amber produced a false alarm no action could ever clear (see FS_Helpers::coverage_gap_count).
// It is stated plainly on whatever verdict wins instead.
$reg_oversize = ( is_array( $meta ) && isset( $meta['skipped_large'] ) ) ? (int) $meta['skipped_large'] : 0;
$has_baseline = ! empty( $baseline );
$scanned = ( $mal_time > 0 ) || ( $reg_time > 0 );
if ( $mal_threats > 0 ) {
$state = 'danger';
/* translators: %d is the number of malware threats found. */
$title = sprintf( _n( 'Malware found — %d threat', 'Malware found — %d threats', $mal_threats, 'ai-cyberguard' ), $mal_threats );
$sub = __( 'Detected by your last malware scan. Open the scanner to review and clean them.', 'ai-cyberguard' );
$btn = __( 'Open malware scanner', 'ai-cyberguard' );
$target = 'gp-malware-scan-anchor';
} elseif ( $mal_time > 0 && $mal_core_issue ) {
// ACG-135-004: a WordPress core file that differs from the official checksum. Not confirmed
// malware (no signature matched), but never a green "All clear" either — it is a hacked core
// or a broken update, and it is ranked above ordinary file changes because it is core.
$state = 'warning';
$title = __( 'WordPress core files have changed', 'ai-cyberguard' );
$sub = __( 'One or more core files do not match the official WordPress release. This is not confirmed malware, but core files should not differ — review them and reinstall WordPress core if the change was not expected.', 'ai-cyberguard' );
$btn = __( 'Review core integrity', 'ai-cyberguard' );
$target = 'gp-malware-scan-anchor';
} elseif ( $mal_time > 0 && $mal_potential > 0 ) {
// ACG-135-004: a high-risk executable pattern that is not confirmed malware. It is shown
// uncollapsed in the results; the headline must not contradict it with "All clear".
$state = 'warning';
/* translators: %d is the number of high-priority items that need review. */
$title = sprintf( _n( '%d high-priority item to review', '%d high-priority items to review', $mal_potential, 'ai-cyberguard' ), $mal_potential );
$sub = __( 'Not confirmed malware, but these patterns can execute code and are worth a look. Open the scanner to review them.', 'ai-cyberguard' );
$btn = __( 'Review findings', 'ai-cyberguard' );
$target = 'gp-malware-scan-anchor';
} elseif ( $has_baseline && $reg_changes > 0 ) {
$state = 'warning';
/* translators: %d is the number of changed files since the last Regular scan. */
$title = sprintf( _n( '%d file change to review', '%d file changes to review', $reg_changes, 'ai-cyberguard' ), $reg_changes );
$sub = __( 'Files changed since your last Regular scan. Review them and confirm the changes were expected by you.', 'ai-cyberguard' );
$btn = __( 'Review changes', 'ai-cyberguard' );
$target = 'gp-regular-scan-anchor';
} elseif ( $mal_time > 0 && $mal_cov_incomplete ) {
// RC-114-05: scanned, no threats, but coverage was not complete → amber, not green.
$state = 'warning';
$title = __( 'No threats found — but the scan was incomplete', 'ai-cyberguard' );
$sub = __( 'Some files or folders were too large or too deep to fully check, so we can\'t yet confirm the whole site is clean. Re-run the scan, or review the coverage notices in the results.', 'ai-cyberguard' );
$btn = __( 'Review scan coverage', 'ai-cyberguard' );
$target = 'gp-malware-scan-anchor';
} elseif ( $reg_time > 0 && $reg_incomplete ) {
// RC-118-05: the Regular file-integrity scan skipped files → incomplete coverage,
// so it must NOT read as a green "All clear".
$state = 'warning';
$title = __( 'File check incomplete', 'ai-cyberguard' );
/* translators: %d is the number of files that could not be checked. */
$sub = sprintf( _n( '%d file could not be read during the last file-integrity check, so it was not verified. Re-run the Regular scan once the file is accessible.', '%d files could not be read during the last file-integrity check, so they were not verified. Re-run the Regular scan once the files are accessible.', max( 1, $reg_skipped ), 'ai-cyberguard' ), max( 1, $reg_skipped ) );
$btn = __( 'Re-run Regular scan', 'ai-cyberguard' );
$target = 'gp-regular-scan-anchor';
} elseif ( ! $has_baseline && $reg_time > 0 ) {
// FIX (2026-06-30): a Regular (file-change) scan ran but NO baseline exists, so it
// could not detect added/changed/deleted files — it has nothing to compare against
// and silently reports "0 changes". Previously this fell through to the green
// "You're protected · All clear" state below, which is FALSE: change detection is OFF.
// Surface it LOUDLY (amber) so the user creates a baseline. (The Malware scan is a
// separate engine and is unaffected.)
$state = 'warning';
$title = __( 'Create a baseline — file-change detection is not active yet', 'ai-cyberguard' );
$sub = __( 'A Regular scan ran, but without a baseline it cannot tell which files were added, changed, or deleted, so it cannot alert you to a new or modified file. Create a baseline now to turn on file-change detection. (Your Malware scan is separate and still works.)', 'ai-cyberguard' );
$btn = __( 'Create baseline', 'ai-cyberguard' );
$target = 'gp-regular-scan-anchor';
} elseif ( $scanned ) {
$state = 'success';
$title = __( "You're protected", 'ai-cyberguard' );
$when = max( $mal_time, $reg_time );
/* translators: %s is a human-readable time difference, e.g. "5 minutes". */
$sub = $when ? sprintf( __( 'Last checked %s ago · All clear.', 'ai-cyberguard' ), human_time_diff( $when, time() ) ) : __( 'All clear.', 'ai-cyberguard' );
$btn = '';
$target = '';
} else {
$state = 'info';
$title = __( 'Run your first malware scan', 'ai-cyberguard' );
$sub = __( 'One click and the AI checks your whole site for malware. It keeps watch on its own from there.', 'ai-cyberguard' );
$btn = __( 'Run first malware scan', 'ai-cyberguard' );
$target = 'gp-malware-scan-anchor';
}
// ACG-137-B2 (self-review round 2): state the over-cap BOUNDARY on whichever verdict won, without
// changing that verdict. This is the reader skipped_large never had: ACG-121 counted these files,
// the count reached the meta, and no surface ever printed it — so a file silently outside content
// monitoring looked identical to no such file. It is deliberately additive text, never a state:
// an ordinary 60 MB backup is a permanent, benign boundary, and my first cut — folding it into
// "incomplete" — produced a permanent amber saying "%d file could not be read ... re-run the scan",
// which was false and unactionable. The dangerous sub-case (a BASELINED file that crosses the cap)
// is reported as CHANGED by ACG-137-B5 and reaches the user through $reg_changes instead.
if ( $reg_oversize > 0 && $reg_time > 0 ) {
$sub .= ' ' . sprintf(
/* translators: %d is the number of files larger than the 50 MB integrity limit. */
_n(
'(%d file is larger than the 50 MB limit, so its contents are not checked — you are still told if it is added, removed, or crosses that limit.)',
'(%d files are larger than the 50 MB limit, so their contents are not checked — you are still told if they are added, removed, or cross that limit.)',
$reg_oversize,
'ai-cyberguard'
),
$reg_oversize
);
}
$palette = array(
'danger' => array( 'bg' => '#f8d7da', 'bd' => '#d63638', 'ic' => '#d63638', 'tx' => '#842029', 'icon' => 'dashicons-warning' ),
'warning' => array( 'bg' => '#fff3cd', 'bd' => '#dba617', 'ic' => '#dba617', 'tx' => '#664d03', 'icon' => 'dashicons-flag' ),
'success' => array( 'bg' => '#d4edda', 'bd' => '#00a32a', 'ic' => '#00a32a', 'tx' => '#0f5132', 'icon' => 'dashicons-yes-alt' ),
'info' => array( 'bg' => '#cfe2ff', 'bd' => '#3b82f6', 'ic' => '#3b82f6', 'tx' => '#084298', 'icon' => 'dashicons-shield' ),
);
$c = isset( $palette[ $state ] ) ? $palette[ $state ] : $palette['info'];
// UX (2026-06-19): the banner is dismissible. The dismissal is remembered against a
// STATE SIGNATURE (state + counts + scan times), so closing it keeps it closed only
// until the underlying situation actually changes — a new scan, a different threat
// count, or a threat being removed brings the relevant banner back automatically.
$banner_sig = $state . '|' . $mal_threats . '|' . $reg_changes . '|' . $mal_time . '|' . $reg_time;
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo '
' . esc_html( $title ) . '
';
echo '
' . esc_html( $sub ) . '
';
// The action button sits BELOW the text (on its own line) so it never overlaps the
// subtitle on narrow admin screens. It lives inside the text column, not as a flex
// sibling of it.
if ( $btn && $target ) {
$solid = ( 'success' !== $state );
$bstyle = $solid
? 'color:#fff; background:' . esc_attr( $c['ic'] ) . '; border:1px solid ' . esc_attr( $c['ic'] ) . ';'
: 'color:' . esc_attr( $c['tx'] ) . '; background:transparent; border:1px solid ' . esc_attr( $c['bd'] ) . ';';
echo '' . esc_html( $btn ) . '';
}
echo '
';
// Dismiss (X). Remembered against the state signature (see above) so it returns on change.
// The action is a SELF-CONTAINED inline onclick (no dependency on any external script
// running, on load order, or on getElementById) so it works regardless of other JS on the
// page — this is the bulletproof fix after a report that the click did nothing. The IIFE
// below is only a belt-and-suspenders backup + the "stay hidden until state changes" load check.
$dismiss_js = "var b=this.closest('.gp-status-banner'); if(b){ b.style.display='none'; try{ if(window.localStorage){ window.localStorage.setItem('gpStatusBannerDismissed', b.getAttribute('data-gp-banner-sig')||''); } }catch(e){} } return false;";
echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- onclick is a hard-coded JS literal (no user data) using only single quotes; esc_attr would corrupt it
echo '
';
?>
';
}
echo '
';
echo ' ';
echo esc_html( sprintf(
/* translators: 1: formatted date and time of the last scan, 2: scan type label. */
__( 'Last scan: %1$s (%2$s scan)', 'ai-cyberguard' ),
wp_date( 'F j, Y \a\t H:i', intval( $last_scan['time'] ) ),
$last_scan['type']
) );
echo '
';
}
}
/**
* Render AI Analysis section
* @since 1.0.0
*/
private function render_ai_analysis( $report ) {
if ( ! class_exists( 'GuardPress_AI_Analyzer' ) ) {
return;
}
// FIX F-104-01 (v1.0.5): use render-safe, network-free readers here.
// This is a page-render path (no user "Analyze" click), so it must NOT
// call is_available()/has_remaining()/get_usage_stats() — those reach
// check_remote_service()/get_remaining(true) and hit guardpress.ai on
// every page load. The authoritative live check runs in the Analyze
// AJAX handler (ajax_analyze_file -> has_remaining()).
$analysis = GuardPress_AI_Analyzer::get_last_analysis();
$is_available = GuardPress_AI_Analyzer::is_available_cached_only();
$has_remaining = GuardPress_AI_Analyzer::has_remaining_cached_only();
$stats = GuardPress_AI_Analyzer::get_usage_stats_cached_only();
$has_changes = ( ( $report['changed'] ?? 0 ) + ( $report['new'] ?? 0 ) + ( $report['deleted'] ?? 0 ) ) > 0;
echo '
';
// Header with help icon
echo '
';
echo '🤖 ';
echo esc_html__( 'AI Analysis', 'ai-cyberguard' );
echo ' ' . esc_html__( 'POWERED BY CLAUDE', 'ai-cyberguard' ) . '';
// Help icon with tooltip - more visible with animation
echo ' ';
echo '?';
echo '';
// Title
echo '
';
echo '🤖 ' . esc_html__( 'What is AI Analysis?', 'ai-cyberguard' ) . '
';
// Main explanation
echo '
';
echo esc_html__( 'AI Analysis is a BONUS feature that uses artificial intelligence (Claude by Anthropic) to deeply analyze your changed files and detect malicious code patterns.', 'ai-cyberguard' );
echo '
💡 ' . esc_html__( 'Pro Tip - Save Your Credits!', 'ai-cyberguard' ) . '
';
echo '
';
echo esc_html__( 'Use AI analysis only for suspicious files! Look for the', 'ai-cyberguard' );
echo ' 🤖 AI Recommended ';
echo esc_html__( 'badge in the scan results table. These are files that have suspicious characteristics.', 'ai-cyberguard' );
echo '
';
echo esc_html__( 'AI Analysis is completely OPTIONAL. The AI CyberGuard scanner works perfectly WITHOUT it! You will still get:', 'ai-cyberguard' );
echo '
';
echo '
';
echo '
' . esc_html__( '✓ Full detection of all changed files', 'ai-cyberguard' ) . '
';
/* translators: %d is the number of free AI analyses included. */
echo sprintf( esc_html__( 'You get %d FREE AI analyses to try this feature. Each analysis reads your changed files and provides detailed security insights.', 'ai-cyberguard' ), esc_html( $stats['limit'] ) );
echo '
';
echo '
';
// PRO upgrade
echo '
';
echo '🚀 ' . esc_html__( 'Need more? PRO gives you 500 analyses/year', 'ai-cyberguard' ) . '';
echo '
';
echo ''; // end tooltip
echo ''; // end help icon
echo '
';
// CSS for tooltip hover and animations
echo '';
// Usage bar
$is_pro_ai = isset( $stats['is_pro'] ) && $stats['is_pro'];
$credits_label = $is_pro_ai ? __( 'PRO AI Credits', 'ai-cyberguard' ) : __( 'Free AI Credits', 'ai-cyberguard' );
echo '
';
// Check if AI is enabled (user opted in)
$is_enabled = GuardPress_AI_Analyzer::is_enabled();
if ( ! $is_enabled ) {
// User hasn't enabled AI yet - show opt-in message
echo '
';
echo '💡 ' . esc_html__( 'This analyzes ALL scan results together. To analyze a specific file, use the "Analyze" button next to that file in the results table below.', 'ai-cyberguard' );
echo '
';
}
} else {
// No analysis yet
echo '
';
if ( $has_changes ) {
echo esc_html__( 'Changes detected! Run AI analysis to get intelligent security insights.', 'ai-cyberguard' );
} else {
echo esc_html__( 'Your site is clean. AI analysis will be available when changes are detected.', 'ai-cyberguard' );
}
echo '
';
echo '💡 ' . esc_html__( 'This analyzes ALL scan results together. To analyze a specific file, use the "Analyze" button next to that file in the results table below.', 'ai-cyberguard' );
echo '
';
}
/**
* Render large dataset notice
*/
/**
* Render results pagination controls
*
* @param int $total_results Total number of results
* @param int $current_limit Current display limit
* @param array $limit_options Available limit options
*/
private function render_results_pagination( $total_results, $current_limit, $limit_options ) {
if ( $total_results === 0 ) {
return;
}
$displayed = min( $current_limit, $total_results );
$base_url = remove_query_arg( 'gp_limit' );
echo '
';
// Left side: Results count
echo '
';
echo '' . sprintf(
/* translators: 1: number of displayed results, 2: total number of results */
esc_html__( 'Displaying %1$d of %2$d results', 'ai-cyberguard' ),
esc_html( $displayed ),
esc_html( $total_results )
) . '';
echo '
';
// Right side: Dropdown selector
echo '
';
echo '';
echo '';
echo '
';
echo '
';
// Warning for large datasets
if ( $displayed > 500 ) {
echo '
';
echo '';
echo esc_html__( 'Displaying a large number of results may slow down the page. Consider using Export to CSV for large datasets.', 'ai-cyberguard' );
echo '
' . sprintf(
/* translators: %d is the number of items in the large result set. */
esc_html__( 'Large result set detected (%d items). For performance, the full list is not displayed.', 'ai-cyberguard' ),
intval( $count )
) . '
';
}
/**
* Render Live Security Monitor section
* Shows real-time security events and file changes for PRO users
*/
private function render_live_traffic() {
// Check if PRO
$is_pro = class_exists( 'GuardPress_License' ) && GuardPress_License::is_pro();
// Run immediate microscan for PRO users
if ( $is_pro && class_exists( 'GuardPress_Realtime_Monitor' ) && method_exists( 'GuardPress_Realtime_Monitor', 'run_microscan' ) ) {
GuardPress_Realtime_Monitor::run_microscan();
}
// Get security events (attacks only - filter out file changes)
$security_events = array();
$file_events = array();
if ( class_exists( 'GuardPress_Security_Log' ) ) {
$all_events = GuardPress_Security_Log::get_recent( 50 );
// Event types to show in file changes section
$file_event_types = array( 'realtime_change', 'file_changed', 'file_new', 'file_deleted' );
// Event types to EXCLUDE from security monitor (informational/monitoring - not attacks)
$monitoring_event_types = array(
'dark_web_check', 'dark_web', 'dark_web_scan',
'uptime_check', 'uptime',
'blacklist_check', 'blacklist_scan',
'vulnerability_scan', 'vulnerability_check',
'backup_completed', 'backup_started',
'scan_completed', 'scan_started',
'baseline_created', 'baseline_refreshed',
'license_renewed', 'license_expired',
'notification_sent', 'notification_error',
'security_score_update',
);
foreach ( $all_events as $event ) {
$type = $event['event_type'] ?? '';
// File changes
if ( in_array( $type, $file_event_types, true ) ) {
if ( count( $file_events ) < 10 ) {
$file_events[] = $event;
}
}
// Skip monitoring/informational events in security monitor
elseif ( in_array( $type, $monitoring_event_types, true ) ) {
continue; // Don't show these in Live Security Monitor
}
// Security events (attacks, blocks, etc.)
else {
if ( count( $security_events ) < 10 ) {
$security_events[] = $event;
}
}
}
}
// NOTE (2026-06-13): a FREE-only "recent blocked IPs" list used to be built here,
// but it is only rendered inside the PRO "Live Security Monitor" section below
// (#gp-security-events, gated by $is_pro). In FREE it was therefore dead work — a
// wasted DB query on every dashboard load — so it was removed. The attack map and
// the counters above query their own data independently and are unaffected.
// Get today's stats
$today_stats = self::get_today_security_stats();
// Get attack origins for map
$attack_origins = self::get_attack_origins();
// ACG-109 (2026-07-01): whether GeoIP location lookup is enabled. It drives
// the map's "turn on GeoIP to see attack locations" note. Default OFF
// (privacy-by-design) — that is why the map has no dots out of the box.
$geoip_on = (bool) get_option( 'guardpress_geoip_enrichment_enabled', false );
?>