PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 3.0.4
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v3.0.4
3.0.5 3.0.4 3.0.3 3.0.2 3.0.1 3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 All 93 releases
vigilante / includes / class-security-analyzer.php

class-security-analyzer.php in Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… 3.0.4, at includes/class-security-analyzer.php

680 lines 25.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Security Analyzer — Orchestrator.
4 *
5 * Runs the six check categories, aggregates their results into a scored
6 * report, persists the result and history, and powers the weekly cron
7 * with a regression-based email digest.
8 *
9 * @package Vigilante
10 * @since 2.1.0
11 */
12
13 // Prevent direct access.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Main entry point for the Security Analyzer.
20 *
21 * Lazy-loaded — instantiated from AJAX handlers and the weekly cron, not from
22 * Vigilante_Main::init_modules(), so the analyzer never runs on front-end hits.
23 */
24 class Vigilante_Security_Analyzer {
25
26 const OPTION_LAST_SCAN = 'vigilante_analyzer_last_scan';
27 const OPTION_HISTORY = 'vigilante_analyzer_history';
28 const OPTION_FIX_LOG = 'vigilante_analyzer_fix_log';
29 const HISTORY_LIMIT = 30;
30 // Legacy constant kept for backward compatibility. The real source of truth
31 // is total_max_points(), which sums the declared "max" of every category
32 // in get_categories(). Bump this only when manually verifying the sum.
33 const TOTAL_MAX_POINTS = 106;
34 const REGRESSION_THRESHOLD = 10; // Points dropped before sending the alert email.
35 /*
36 * Highest score a site can show while the self-protection check reports
37 * tampering: every other result of this report was computed by the same
38 * code whose files were reported as changed, so a high number next to it
39 * would be a lie. 29 is the top of grade E in compute_grade().
40 */
41 const SCORE_CAP_ON_TAMPER = 29;
42
43 /**
44 * Sum of the declared "max" of every category. This is the canonical
45 * maximum a scan can earn. Using this instead of the constant prevents
46 * the desync we hit in 2.6.0 (a new check raised the internal category
47 * max but the global total stayed at the pre-bump value).
48 *
49 * @return int
50 */
51 public static function total_max_points() {
52 $total = 0;
53 foreach ( self::get_categories() as $meta ) {
54 $total += (int) $meta['max'];
55 }
56 return $total;
57 }
58
59 /**
60 * @var Vigilante_Settings
61 */
62 private $settings;
63
64 /**
65 * @var Vigilante_Activity_Log|null
66 */
67 private $activity_log;
68
69 /**
70 * Metadata about each category used by the UI (label + weight).
71 *
72 * @return array<string,array{slug:string,label:string,max:int}>
73 */
74 public static function get_categories() {
75 return array(
76 'ssl' => array(
77 'slug' => 'ssl',
78 'label' => __( 'SSL / TLS', 'vigilante' ),
79 'max' => 12,
80 ),
81 'headers' => array(
82 'slug' => 'headers',
83 'label' => __( 'HTTP Security Headers', 'vigilante' ),
84 'max' => 18,
85 ),
86 'wp_exposure' => array(
87 'slug' => 'wp_exposure',
88 'label' => __( 'WordPress Exposure', 'vigilante' ),
89 'max' => 18,
90 ),
91 'access' => array(
92 'slug' => 'access',
93 'label' => __( 'Access & Authentication', 'vigilante' ),
94 'max' => 20,
95 ),
96 'files' => array(
97 'slug' => 'files',
98 'label' => __( 'Sensitive Files', 'vigilante' ),
99 'max' => 10,
100 ),
101 'internal' => array(
102 'slug' => 'internal',
103 'label' => __( 'Internal Checks (exclusive)', 'vigilante' ),
104 // Sum of the max values of every check in
105 // Vigilante_SA_Category_Internal. Update when adding/removing
106 // checks or changing their max value.
107 // 3.0.0: 30 -> 40 (self_integrity check added, worth 10: the
108 // integrity of the plugin that runs every other check).
109 'max' => 40,
110 ),
111 'reputation' => array(
112 'slug' => 'reputation',
113 'label' => __( 'Reputation / Blacklists', 'vigilante' ),
114 'max' => 0,
115 'info_only' => true,
116 ),
117 );
118 }
119
120 /**
121 * @param Vigilante_Settings $settings
122 * @param Vigilante_Activity_Log|null $activity_log
123 */
124 public function __construct( Vigilante_Settings $settings, $activity_log = null ) {
125 $this->settings = $settings;
126 $this->activity_log = $activity_log;
127 $this->require_dependencies();
128 }
129
130 /**
131 * Load category + helper classes (one-time per request).
132 */
133 private function require_dependencies() {
134 $dir = VIGILANTE_INCLUDES_DIR . 'security-analyzer/';
135 require_once $dir . 'class-sa-check-result.php';
136 require_once $dir . 'class-sa-helpers.php';
137 require_once $dir . 'class-sa-category-ssl.php';
138 require_once $dir . 'class-sa-category-headers.php';
139 require_once $dir . 'class-sa-category-wp-exposure.php';
140 require_once $dir . 'class-sa-category-access.php';
141 require_once $dir . 'class-sa-category-files.php';
142 require_once $dir . 'class-sa-category-internal.php';
143 require_once $dir . 'class-sa-category-reputation.php';
144 }
145
146 /**
147 * Run the scan in the requested phase and return the aggregated report.
148 *
149 * @param string $phase 'fast' | 'slow' | 'all'.
150 * @return array Report (see build_report()).
151 */
152 public function run_scan( $phase = 'all' ) {
153 if ( ! in_array( $phase, array( 'fast', 'slow', 'all' ), true ) ) {
154 $phase = 'all';
155 }
156
157 Vigilante_SA_Helpers::reset_cache();
158 $started = time();
159
160 $results = array();
161
162 $cat_ssl = new Vigilante_SA_Category_SSL( $this->settings );
163 $cat_headers = new Vigilante_SA_Category_Headers( $this->settings );
164 $cat_expose = new Vigilante_SA_Category_WP_Exposure( $this->settings );
165 $cat_access = new Vigilante_SA_Category_Access( $this->settings );
166 $cat_files = new Vigilante_SA_Category_Files( $this->settings );
167 $cat_intern = new Vigilante_SA_Category_Internal( $this->settings, $this->activity_log );
168 $cat_reput = new Vigilante_SA_Category_Reputation( $this->settings );
169
170 foreach ( $cat_ssl->run( $phase ) as $r ) {
171 $results[] = $r;
172 }
173 foreach ( $cat_headers->run( $phase ) as $r ) {
174 $results[] = $r;
175 }
176 foreach ( $cat_expose->run( $phase ) as $r ) {
177 $results[] = $r;
178 }
179 foreach ( $cat_access->run( $phase ) as $r ) {
180 $results[] = $r;
181 }
182 foreach ( $cat_files->run( $phase ) as $r ) {
183 $results[] = $r;
184 }
185 foreach ( $cat_intern->run( $phase ) as $r ) {
186 $results[] = $r;
187 }
188 foreach ( $cat_reput->run( $phase ) as $r ) {
189 $results[] = $r;
190 }
191
192 $report = $this->build_report( $results, $phase, $started );
193 $report['ran_at'] = $started;
194 $report['phase'] = $phase;
195 $report['elapsed'] = max( 0, time() - $started );
196
197 // Merge-persist: 'fast' and 'slow' phases each update part of the report;
198 // 'all' replaces everything. Dashboard widget shows whatever's latest.
199 $this->persist_scan( $report, $phase );
200
201 // Push to history only when the whole scan has finished (either 'all' in one call,
202 // or a 'slow' phase that immediately follows a 'fast' phase within the same minute).
203 if ( 'all' === $phase ) {
204 $this->push_history( $report );
205 } elseif ( 'slow' === $phase ) {
206 // The slow phase closes a scan the fast one started, so what goes
207 // to the history is the two merged, as persist_scan() has just
208 // stored them. The report of this phase alone carries only its own
209 // checks, and the trend showed every manual scan as a collapse.
210 $this->push_history( $this->get_last_scan() );
211 }
212
213 return $report;
214 }
215
216 /**
217 * Aggregate check results into the scan report structure.
218 *
219 * @param Vigilante_SA_Check_Result[] $results
220 * @param string $phase
221 * @param int $started Unix timestamp.
222 * @return array
223 */
224 private function build_report( $results, $phase, $started ) {
225 $cat_meta = self::get_categories();
226
227 $categories = array();
228 foreach ( $cat_meta as $slug => $meta ) {
229 $categories[ $slug ] = array(
230 'slug' => $slug,
231 'label' => $meta['label'],
232 'max' => $meta['max'],
233 'earned' => 0,
234 'checks' => array(),
235 'counts' => array(
236 'pass' => 0,
237 'warn' => 0,
238 'fail' => 0,
239 'info' => 0,
240 'skip' => 0,
241 ),
242 );
243 }
244
245 $total_earned = 0;
246 $total_max = 0;
247 $counts = array(
248 'pass' => 0,
249 'warn' => 0,
250 'fail' => 0,
251 'info' => 0,
252 'skip' => 0,
253 );
254
255 foreach ( $results as $r ) {
256 if ( ! ( $r instanceof Vigilante_SA_Check_Result ) ) {
257 continue;
258 }
259 $slug = $r->category;
260 if ( ! isset( $categories[ $slug ] ) ) {
261 continue;
262 }
263 $categories[ $slug ]['checks'][] = $r->to_array();
264 $categories[ $slug ]['counts'][ $r->state ] = isset( $categories[ $slug ]['counts'][ $r->state ] )
265 ? $categories[ $slug ]['counts'][ $r->state ] + 1
266 : 1;
267 $counts[ $r->state ] = isset( $counts[ $r->state ] ) ? $counts[ $r->state ] + 1 : 1;
268
269 if ( $r->counts_for_score() ) {
270 $categories[ $slug ]['earned'] += $r->score;
271 $total_earned += $r->score;
272 $total_max += $r->max;
273 }
274 }
275
276 // Normalize against the declared category max so skipped checks don't erode the score.
277 $declared_max = self::total_max_points();
278 $grade = Vigilante_SA_Helpers::compute_grade( $total_earned, $declared_max );
279
280 // Self-protection caps the score (see SCORE_CAP_ON_TAMPER). The same
281 // cap is applied when phases are merged, in rebuild_from_categories().
282 $capped_by = '';
283 foreach ( $results as $r ) {
284 if ( $r instanceof Vigilante_SA_Check_Result
285 && 'self_integrity' === $r->id
286 && Vigilante_SA_Check_Result::STATE_FAIL === $r->state ) {
287 $capped_by = 'self_integrity';
288 break;
289 }
290 }
291 if ( 'self_integrity' === $capped_by && $grade['score'] > self::SCORE_CAP_ON_TAMPER ) {
292 $grade['score'] = self::SCORE_CAP_ON_TAMPER;
293 $grade['grade'] = 'E';
294 }
295
296 return array(
297 'ran_at' => $started,
298 'phase' => $phase,
299 'total_earned' => $total_earned,
300 'total_max' => $declared_max,
301 'total_evaluated'=> $total_max, // Actual evaluated max (excluding skipped).
302 'score' => $grade['score'],
303 'grade' => $grade['grade'],
304 'capped_by' => $capped_by,
305 'counts' => $counts,
306 'categories' => $categories,
307 );
308 }
309
310 /**
311 * Merge the new partial/full scan with whatever was last persisted.
312 * Fast + slow phases arrive separately from the UI; we store a consistent
313 * merged report so reloading the Dashboard shows complete data.
314 *
315 * @param array $report
316 * @param string $phase
317 */
318 private function persist_scan( array $report, $phase ) {
319 if ( 'all' === $phase ) {
320 update_option( self::OPTION_LAST_SCAN, $report, false );
321 return;
322 }
323
324 $existing = $this->get_last_scan();
325 if ( ! is_array( $existing ) ) {
326 update_option( self::OPTION_LAST_SCAN, $report, false );
327 return;
328 }
329
330 // Merge: only replace categories whose checks are actually present in the new phase.
331 foreach ( $report['categories'] as $slug => $cat ) {
332 if ( empty( $cat['checks'] ) ) {
333 continue;
334 }
335 // Track which check ids were produced now so we can overwrite them selectively.
336 $new_ids = array();
337 foreach ( $cat['checks'] as $c ) {
338 if ( isset( $c['id'] ) ) {
339 $new_ids[ $c['id'] ] = true;
340 }
341 }
342
343 // Start from existing category bucket (preserve other-phase checks).
344 if ( ! isset( $existing['categories'][ $slug ] ) ) {
345 $existing['categories'][ $slug ] = $cat;
346 continue;
347 }
348 $merged_checks = array();
349 foreach ( (array) $existing['categories'][ $slug ]['checks'] as $old_c ) {
350 if ( isset( $old_c['id'] ) && isset( $new_ids[ $old_c['id'] ] ) ) {
351 continue; // Will be replaced below.
352 }
353 $merged_checks[] = $old_c;
354 }
355 foreach ( $cat['checks'] as $new_c ) {
356 $merged_checks[] = $new_c;
357 }
358 $existing['categories'][ $slug ]['checks'] = $merged_checks;
359 }
360
361 // Recompute totals from the merged categories.
362 $rebuilt = $this->rebuild_from_categories( $existing['categories'] );
363 $existing = array_merge( $existing, $rebuilt );
364 $existing['ran_at'] = $report['ran_at'];
365 $existing['phase'] = $phase;
366 $existing['elapsed'] = isset( $report['elapsed'] ) ? $report['elapsed'] : 0;
367
368 update_option( self::OPTION_LAST_SCAN, $existing, false );
369 }
370
371 /**
372 * Recompute totals and grade from a categories array (used when merging phases).
373 *
374 * @param array $categories
375 * @return array subset with total_earned, total_max, total_evaluated, score, grade, counts.
376 */
377 private function rebuild_from_categories( array $categories ) {
378 $total_earned = 0;
379 $total_evaluated = 0;
380 $counts = array(
381 'pass' => 0,
382 'warn' => 0,
383 'fail' => 0,
384 'info' => 0,
385 'skip' => 0,
386 );
387
388 // Resolve the canonical "max" of every category from the declared meta.
389 // Without this, merging fast/slow phases preserves a stale "max" from
390 // the previous scan, which is what produced the 28/22 desync after
391 // 2.6.0 added the closed_plugins check.
392 $cat_meta = self::get_categories();
393
394 foreach ( $categories as $slug => $cat ) {
395 $cat_earned = 0;
396 $cat_counts = array(
397 'pass' => 0,
398 'warn' => 0,
399 'fail' => 0,
400 'info' => 0,
401 'skip' => 0,
402 );
403 foreach ( (array) $cat['checks'] as $c ) {
404 $state = isset( $c['state'] ) ? $c['state'] : Vigilante_SA_Check_Result::STATE_SKIP;
405 $cat_counts[ $state ] = isset( $cat_counts[ $state ] ) ? $cat_counts[ $state ] + 1 : 1;
406 $counts[ $state ] = isset( $counts[ $state ] ) ? $counts[ $state ] + 1 : 1;
407
408 if ( Vigilante_SA_Check_Result::STATE_INFO === $state || Vigilante_SA_Check_Result::STATE_SKIP === $state ) {
409 continue;
410 }
411 $cat_earned += isset( $c['score'] ) ? (int) $c['score'] : 0;
412 $total_earned += isset( $c['score'] ) ? (int) $c['score'] : 0;
413 $total_evaluated += isset( $c['max'] ) ? (int) $c['max'] : 0;
414 }
415 $categories[ $slug ]['earned'] = $cat_earned;
416 $categories[ $slug ]['counts'] = $cat_counts;
417
418 // Force the canonical max so old cached scans get repaired the
419 // moment they're touched (no need to wait for a clean "all" phase).
420 if ( isset( $cat_meta[ $slug ]['max'] ) ) {
421 $categories[ $slug ]['max'] = (int) $cat_meta[ $slug ]['max'];
422 }
423 }
424
425 $total_max = self::total_max_points();
426 $grade = Vigilante_SA_Helpers::compute_grade( $total_earned, $total_max );
427
428 // Self-protection caps the score (see SCORE_CAP_ON_TAMPER).
429 $capped_by = '';
430 foreach ( $categories as $cat ) {
431 foreach ( (array) $cat['checks'] as $c ) {
432 if ( 'self_integrity' === ( isset( $c['id'] ) ? $c['id'] : '' )
433 && Vigilante_SA_Check_Result::STATE_FAIL === ( isset( $c['state'] ) ? $c['state'] : '' ) ) {
434 $capped_by = 'self_integrity';
435 break 2;
436 }
437 }
438 }
439 if ( 'self_integrity' === $capped_by && $grade['score'] > self::SCORE_CAP_ON_TAMPER ) {
440 $grade['score'] = self::SCORE_CAP_ON_TAMPER;
441 $grade['grade'] = 'E';
442 }
443
444 return array(
445 'categories' => $categories,
446 'total_earned' => $total_earned,
447 'total_max' => $total_max,
448 'total_evaluated'=> $total_evaluated,
449 'score' => $grade['score'],
450 'grade' => $grade['grade'],
451 'capped_by' => $capped_by,
452 'counts' => $counts,
453 );
454 }
455
456 /**
457 * Append a minimal history entry (no per-check detail) to the circular buffer.
458 *
459 * @param array $report
460 */
461 private function push_history( array $report ) {
462 $history = $this->get_score_history( self::HISTORY_LIMIT );
463 if ( ! is_array( $history ) ) {
464 $history = array();
465 }
466
467 $entry = array(
468 'ran_at' => (int) $report['ran_at'],
469 'score' => (int) $report['score'],
470 'grade' => (string) $report['grade'],
471 'total_earned' => (int) $report['total_earned'],
472 'categories' => array(),
473 );
474 foreach ( $report['categories'] as $slug => $cat ) {
475 $entry['categories'][ $slug ] = array(
476 'earned' => (int) $cat['earned'],
477 'max' => (int) $cat['max'],
478 );
479 }
480
481 $history[] = $entry;
482 if ( count( $history ) > self::HISTORY_LIMIT ) {
483 $history = array_slice( $history, -self::HISTORY_LIMIT );
484 }
485 update_option( self::OPTION_HISTORY, $history, false );
486 }
487
488 /**
489 * Return the last persisted scan, or an empty placeholder structure.
490 *
491 * @return array
492 */
493 public function get_last_scan() {
494 $raw = get_option( self::OPTION_LAST_SCAN, null );
495 if ( ! is_array( $raw ) ) {
496 return array(
497 'ran_at' => 0,
498 'score' => 0,
499 'grade' => '',
500 'total_earned' => 0,
501 'total_max' => self::total_max_points(),
502 'counts' => array(
503 'pass' => 0,
504 'warn' => 0,
505 'fail' => 0,
506 'info' => 0,
507 'skip' => 0,
508 ),
509 'categories' => array(),
510 );
511 }
512 return $raw;
513 }
514
515 /**
516 * Return history (oldest first, max = HISTORY_LIMIT).
517 *
518 * @param int $limit
519 * @return array
520 */
521 public function get_score_history( $limit = self::HISTORY_LIMIT ) {
522 $raw = get_option( self::OPTION_HISTORY, array() );
523 if ( ! is_array( $raw ) ) {
524 return array();
525 }
526 $limit = max( 1, (int) $limit );
527 return array_slice( $raw, -$limit );
528 }
529
530 /**
531 * Return the catalog for UI (check labels, max points, fix links).
532 * Built from a single dry-run to avoid maintaining a duplicate mapping.
533 *
534 * @return array
535 */
536 public function get_catalog() {
537 $cats = self::get_categories();
538 $out = array();
539 foreach ( $cats as $slug => $meta ) {
540 $out[ $slug ] = array(
541 'slug' => $slug,
542 'label' => $meta['label'],
543 'max' => $meta['max'],
544 'checks' => array(),
545 );
546 }
547 return $out;
548 }
549
550 /**
551 * Weekly cron handler — run a full scan and email the admin when the score
552 * has dropped by >= REGRESSION_THRESHOLD points vs the previous history entry,
553 * or when new critical failures appeared.
554 */
555 public function cron_weekly_scan() {
556 $previous = $this->get_last_scan();
557 $report = $this->run_scan( 'all' );
558
559 // Bail if notifications aren't wanted.
560 $analyzer_settings = (array) $this->settings->get_section( 'security_analyzer' );
561 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
562 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
563
564 if ( ! $weekly_enabled || ! $email_enabled ) {
565 return;
566 }
567
568 if ( empty( $previous['score'] ) ) {
569 return; // First run: never email.
570 }
571
572 $delta = (int) $previous['score'] - (int) $report['score'];
573 $new_fails = $this->diff_new_failures( $previous, $report );
574
575 if ( $delta < self::REGRESSION_THRESHOLD && empty( $new_fails ) ) {
576 return;
577 }
578
579 $this->send_regression_email( $previous, $report, $new_fails );
580 }
581
582 /**
583 * Collect check ids that are FAIL now but weren't FAIL (were PASS/WARN/INFO/SKIP) before.
584 *
585 * @param array $prev
586 * @param array $curr
587 * @return array<int,array{label:string,category:string,id:string}>
588 */
589 private function diff_new_failures( array $prev, array $curr ) {
590 $prev_states = array();
591 foreach ( (array) ( $prev['categories'] ?? array() ) as $slug => $cat ) {
592 foreach ( (array) ( $cat['checks'] ?? array() ) as $c ) {
593 if ( isset( $c['id'] ) ) {
594 $prev_states[ $c['id'] ] = isset( $c['state'] ) ? $c['state'] : '';
595 }
596 }
597 }
598
599 $diffs = array();
600 foreach ( (array) ( $curr['categories'] ?? array() ) as $slug => $cat ) {
601 foreach ( (array) ( $cat['checks'] ?? array() ) as $c ) {
602 if ( ! isset( $c['id'], $c['state'] ) ) {
603 continue;
604 }
605 if ( Vigilante_SA_Check_Result::STATE_FAIL !== $c['state'] ) {
606 continue;
607 }
608 $was = isset( $prev_states[ $c['id'] ] ) ? $prev_states[ $c['id'] ] : '';
609 if ( Vigilante_SA_Check_Result::STATE_FAIL === $was ) {
610 continue;
611 }
612 $diffs[] = array(
613 'id' => $c['id'],
614 'label' => isset( $c['label'] ) ? $c['label'] : $c['id'],
615 'category' => $slug,
616 );
617 }
618 }
619 return $diffs;
620 }
621
622 /**
623 * Send the regression alert email.
624 *
625 * @param array $prev Previous scan.
626 * @param array $curr Current scan.
627 * @param array $new_fails New failures diff.
628 */
629 private function send_regression_email( array $prev, array $curr, array $new_fails ) {
630 if ( ! class_exists( 'Vigilante_Email_Template' ) ) {
631 require_once VIGILANTE_INCLUDES_DIR . 'class-email-template.php';
632 }
633
634 $to = Vigilante_Email_Template::get_admin_recipients();
635 if ( empty( $to ) ) {
636 return;
637 }
638
639 $subject = sprintf(
640 /* translators: 1: previous grade, 2: previous score, 3: current grade, 4: current score */
641 __( '[Vigilant] Security Score dropped from %1$s (%2$d) to %3$s (%4$d)', 'vigilante' ),
642 $prev['grade'],
643 (int) $prev['score'],
644 $curr['grade'],
645 (int) $curr['score']
646 );
647
648 $body = '<p>' . esc_html(
649 sprintf(
650 /* translators: 1: site name */
651 __( 'Vigilant ran the weekly Security Check on %s and the result changed.', 'vigilante' ),
652 get_bloginfo( 'name' )
653 )
654 ) . '</p>';
655
656 $body .= Vigilante_Email_Template::data_table(
657 array(
658 __( 'Previous Score', 'vigilante' ) => $prev['grade'] . ' — ' . (int) $prev['score'] . '/100',
659 __( 'Current Score', 'vigilante' ) => $curr['grade'] . ' — ' . (int) $curr['score'] . '/100',
660 __( 'Points lost', 'vigilante' ) => (int) $prev['score'] - (int) $curr['score'],
661 __( 'New failing checks', 'vigilante' ) => count( $new_fails ),
662 )
663 );
664
665 if ( ! empty( $new_fails ) ) {
666 $body .= '<h3>' . esc_html__( 'Checks that started failing', 'vigilante' ) . '</h3>';
667 $body .= '<ul>';
668 foreach ( $new_fails as $f ) {
669 $body .= '<li><strong>' . esc_html( $f['label'] ) . '</strong> <em>(' . esc_html( $f['category'] ) . ')</em></li>';
670 }
671 $body .= '</ul>';
672 }
673
674 $report_url = admin_url( 'admin.php?page=vigilante&tab=dashboard#vigilante-analyzer' );
675 $body .= '<p><a href="' . esc_url( $report_url ) . '" style="display:inline-block;background:#2271b1;color:#fff;padding:8px 16px;text-decoration:none;border-radius:4px;">' . esc_html__( 'View full report', 'vigilante' ) . '</a></p>';
676
677 Vigilante_Email_Template::send( $to, $subject, __( 'Security Check regression detected', 'vigilante' ), $body, true );
678 }
679 }
680