value * @type string $nonce Nonce action * } */ public static function render_form_button( $args ) { $defaults = array( 'cmd' => '', 'label' => '', 'icon' => '', 'class' => 'secondary', 'size' => 'lg', 'extra' => array(), 'nonce' => 'guardpress_nonce_action', ); $args = wp_parse_args( $args, $defaults ); $btn_class = 'gp-btn gp-btn-' . esc_attr( $args['class'] ); if ( ! empty( $args['size'] ) ) { $btn_class .= ' gp-btn-' . esc_attr( $args['size'] ); } echo '
'; wp_nonce_field( $args['nonce'], 'guardpress_nonce' ); echo ''; echo ''; // Extra hidden fields foreach ( $args['extra'] as $key => $value ) { echo ''; } echo '
'; } /** * Render a link button */ public static function render_link_button( $url, $label, $icon = '', $class = 'secondary', $size = 'lg' ) { $btn_class = 'gp-btn gp-btn-' . esc_attr( $class ); if ( ! empty( $size ) ) { $btn_class .= ' gp-btn-' . esc_attr( $size ); } echo ''; if ( ! empty( $icon ) ) { echo ''; } echo esc_html( $label ); echo ''; } /** * Render scanner action buttons */ public static function render_scanner_actions( $nonce_action ) { // Generate nonce for batch scan AJAX $batch_nonce = wp_create_nonce( 'guardpress_batch_scan' ); // ============ MALWARE SCAN SECTION (ABOVE BASELINE) ============ self::render_malware_scan_section( $batch_nonce ); echo '
'; echo '

' . esc_html__( 'πŸ‘‰ New here? Run a Malware Scan (above) first, then click β€œCreate Baseline.” The baseline records your current files as the clean reference, so the scanner can spot anything that changes later.', 'ai-cyberguard' ) . '

'; // Create baseline - AJAX button echo ''; // Refresh baseline - AJAX button echo ''; // Regular scan - AJAX button echo ''; // Full scan - AJAX button echo ''; // Settings link self::render_link_button( admin_url( 'admin.php?page=guardpress_settings' ), __( 'Settings', 'ai-cyberguard' ), 'admin-generic', 'secondary' ); echo '
'; // Progress bar container (hidden by default) echo ''; // #gp-scan-progress-container // Add spinner animation CSS echo ''; // Add batch scan JavaScript self::render_batch_scan_js(); } /** * Render batch scan JavaScript */ private static function render_batch_scan_js() { ?> '; // UX (2026-06-19): the #1 source of confusion was "I ran a Malware Scan and it // was clean, so why does Regular Scan show files?" β€” because these are two // DIFFERENT scans. Spell out the difference in plain language before the // per-button list, so a changed file is not mistaken for malware (and vice-versa). echo '

'; echo '' . esc_html__( 'Two different scans β€” what’s the difference?', 'ai-cyberguard' ) . '
'; echo esc_html__( 'The Malware Scan (purple box above) looks for known malicious code inside your files. The scans below β€” Regular Scan and Full Scan β€” do something different: they compare your files against your saved Baseline and report any file that was changed, added, or removed. Most file changes are completely harmless (WordPress, plugin or theme updates), so a file listed here is NOT necessarily malware β€” it simply changed since your baseline. The two scans work together: malware scanning catches known bad code, and file-change scanning catches tampering even when the code is not yet a known signature.', 'ai-cyberguard' ); echo '

'; echo '

'; echo '' . esc_html__( 'Create Baseline', 'ai-cyberguard' ) . ' – ' . esc_html__( 'records your current files as the clean reference β€” do this once, ideally right after a clean Malware Scan.', 'ai-cyberguard' ) . '
'; echo '' . esc_html__( 'Refresh Baseline', 'ai-cyberguard' ) . ' – ' . esc_html__( 'click this after legitimate WordPress, plugin, or theme updates, so the scanner learns the new files and stops flagging them as changes (avoids false alarms).', 'ai-cyberguard' ) . '
'; echo '' . esc_html__( 'Regular Scan', 'ai-cyberguard' ) . ' – ' . esc_html__( 'checks only risky file types (PHP, JS, configs). Fast and recommended.', 'ai-cyberguard' ) . '
'; echo '' . esc_html__( 'Full Scan', 'ai-cyberguard' ) . ' – ' . esc_html__( 'checks every file (slower). Use only if you suspect your site was hacked.', 'ai-cyberguard' ) . '

'; echo ''; } /** * Render Malware Scan Section (above baseline buttons) * * @param string $nonce Batch scan nonce */ public static function render_malware_scan_section( $nonce ) { // Get signature stats $sig_stats = array( 'total' => 50 ); if ( class_exists( 'GuardPress_Malware_Scanner' ) ) { $sig_stats = GuardPress_Malware_Scanner::get_signature_stats(); } // Check if we have last scan results $last_scan = null; if ( class_exists( 'GuardPress_Malware_Scanner' ) ) { $last_scan = GuardPress_Malware_Scanner::get_last_scan(); } // ───────────────────────────────────────────────────────────────────────────────────────── // ACG-149-R36-E (pre-release audit 2026-07-27) β€” SHOW WHAT THE SCHEDULED SCAN FOUND. // // The scheduled scan malware-scans the files it finds changed, and it does find webshells. // Until now that verdict reached the user through exactly one channel: the alert email. And // `email_enabled` ships as 0, so on a DEFAULT install the product positively identified a // backdoor and then had nowhere to put it β€” the dashboard went on saying "1 file change // detected". The persistence layer for this was written last round and had NO CALLER // anywhere in the plugin, so the behaviour was still fully live. // // Rendered ABOVE the scan card and separately from it, because it answers a different // question: the card reports the last scan the USER ran, this reports what ran on its own // while they were away. Deliberately not merged into the card's tri-state β€” the two have // different coverage (whole site vs changed files only) and merging them would let one // scan's coverage claim describe the other's findings, which is the cross-surface // contradiction ACG-138-R2-03 exists to prevent. $gp_sched = ( class_exists( 'GuardPress_Malware_Scanner' ) && method_exists( 'GuardPress_Malware_Scanner', 'get_scheduled_findings' ) ) ? GuardPress_Malware_Scanner::get_scheduled_findings() : array(); $gp_sched_files = ( is_array( $gp_sched ) && ! empty( $gp_sched['files'] ) && is_array( $gp_sched['files'] ) ) ? $gp_sched['files'] : array(); // ACG-149-R37-P: every row is reduced to two plain strings before anything renders. The record // is persisted state; a corrupt or hostile value (an object) previously reached a `(string)` cast // mid-render and threw an uncaught Error β€” a white screen after the opening
was flushed. $gp_rows = array(); foreach ( $gp_sched_files as $gp_r ) { if ( ! is_array( $gp_r ) ) { continue; } $gp_rows[] = array( 'path' => ( isset( $gp_r['path'] ) && is_string( $gp_r['path'] ) ) ? $gp_r['path'] : '', 'name' => ( isset( $gp_r['name'] ) && is_string( $gp_r['name'] ) ) ? $gp_r['name'] : '', ); } if ( ! empty( $gp_rows ) ) : ?>
🚨
0 ) { $gp_sched_time = ( 0 === $gp_sched_time ) ? (int) $gp_fr['first'] : min( $gp_sched_time, (int) $gp_fr['first'] ); } } if ( 0 === $gp_sched_time ) { $gp_sched_time = ( isset( $gp_sched['time'] ) && is_numeric( $gp_sched['time'] ) ) ? (int) $gp_sched['time'] : 0; } if ( $gp_sched_time > 0 && $gp_sched_time <= ( time() + 300 ) ) : ?>

0 ) : ?>

πŸ›‘οΈ

0 ) ? 'threat' // confirmed malware β†’ red : ( empty( $gp_sum['is_clean'] ) ? 'review' : 'clean' ); // needs attention β†’ amber // otherwise β†’ green $gp_palette = array( 'clean' => array( 'bg' => 'rgba(34, 197, 94, 0.2)', 'br' => 'rgba(34, 197, 94, 0.3)', 'icon' => 'βœ…' ), 'review' => array( 'bg' => 'rgba(245, 158, 11, 0.2)', 'br' => 'rgba(245, 158, 11, 0.35)', 'icon' => '⚠️' ), 'threat' => array( 'bg' => 'rgba(239, 68, 68, 0.2)', 'br' => 'rgba(239, 68, 68, 0.3)', 'icon' => '🚨' ), ); $gp_pal = $gp_palette[ $gp_state ]; ?>
0 leaves total_threats at 0 β€” // a modified core file carries no signature match) fell through to // "No malware β€” 1 item to review" while the status banner said // "WordPress core files have changed" and the results panel said // "CRITICAL: Reinstall WordPress immediately". Three surfaces, same // scan, one of them calling a hacked core an optional review item. // The reviewer's objection: a customer cannot tell those three // statements apart, and the contradiction is trivial to screenshot. // The arms below now follow the SAME severity order as the ladder in // generate_summary() β€” malware > core integrity > coverage > review β€” // so the card can no longer rank a core issue below a benign extract(). $gp_s = $last_scan['summary']; $gp_t = (int) ( $gp_s['total_threats'] ?? 0 ); $gp_rv = (int) ( $gp_s['review_total'] ?? 0 ); $gp_cm = (int) ( $gp_s['core_modified'] ?? 0 ); $gp_cu = (int) ( $gp_s['core_unknown'] ?? 0 ); if ( $gp_t > 0 ) { printf( /* translators: %d is the number of confirmed malware threats found by the scan */ esc_html( _n( '%d threat found', '%d threats found', $gp_t, 'ai-cyberguard' ) ), esc_html( $gp_t ) ); } elseif ( $gp_cm > 0 ) { esc_html_e( 'WordPress core files have changed β€” reinstall WordPress', 'ai-cyberguard' ); } elseif ( ( $gp_pi = (int) ( $gp_s['potential_items'] ?? 0 ) ) > 0 ) { // ACG-138-R2-03: the flagship case. A HIGH/CRITICAL suspicious finding read // exactly like a benign extract() in a premium plugin ("No malware β€” 1 item // to review"), which is the understatement ACG-116-T1/ACG-122 exist to stop. // ACG-138-R2-03-adv (adversarial review, 2026-07-17): potential_items comes // BEFORE core_unknown here, to match generate_summary()'s ladder EXACTLY. The // arms were previously swapped (core_unknown first), so a scan with BOTH // core_unknown>0 AND potential_items>0 showed the core-unknown headline on the // card while the results panel led with potential_items β€” the very // cross-surface contradiction R2-03 exists to prevent. printf( /* translators: %d is the number of serious items shown as potential threats */ esc_html( _n( 'No confirmed malware β€” %d item needs checking now', 'No confirmed malware β€” %d items need checking now', $gp_pi, 'ai-cyberguard' ) ), esc_html( $gp_pi ) ); } elseif ( $gp_cu > 0 ) { esc_html_e( 'A file in your WordPress core folders is not part of the official release', 'ai-cyberguard' ); } elseif ( empty( $gp_s['coverage_complete'] ) ) { esc_html_e( 'No malware found β€” but the scan was incomplete', 'ai-cyberguard' ); } elseif ( $gp_rv > 0 ) { printf( /* translators: %d is the number of items that need review (not confirmed malware) */ esc_html( _n( 'No malware β€” %d item to review', 'No malware β€” %d items to review', $gp_rv, 'ai-cyberguard' ) ), esc_html( $gp_rv ) ); } else { esc_html_e( 'Scan complete β€” review the results', 'ai-cyberguard' ); } } ?>
πŸ’‘

0 ) { $days_since = floor( ( time() - $last_threat_update ) / 86400 ); if ( $days_since > 0 ) { $update_info = sprintf( /* translators: %d is the number of days since threat signatures were last updated */ __( 'Threat signatures last updated %d days ago.', 'ai-cyberguard' ), $days_since ); } else { $update_info = __( 'Threat signatures updated today.', 'ai-cyberguard' ); } } else { $update_info = __( 'Threat signatures never updated. Click "Refresh" in Threat Intelligence section below.', 'ai-cyberguard' ); } ?>
⏱️