PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/controller/class-scan.php +313 -167 5.9.0 → 6.3.0 View file →
@@ -20,8 +20,9 @@
20 20 use WP_Defender\Model\Scan as Model_Scan;
21 21 use WP_Defender\Behavior\Scan\Core_Integrity;
22 22 use WP_Defender\Component\Network_Cron_Manager;
23 23 use WP_Defender\Component\Scan as Scan_Component;
24 +use WP_Defender\Component\Rate as Rate_Component;
24 25 use WP_Defender\Model\Setting\Scan as Scan_Settings;
25 26 use WP_Defender\Model\Notification\Malware_Report;
26 27 use WP_Defender\Component\Config\Config_Hub_Helper;
27 28 use WP_Defender\Helper\Analytics\Scan as Scan_Analytics;
@@ -37,9 +38,22 @@
37 38 use Formats;
38 39 use Scan_Upsell;
39 40
40 41 public const SCAN_LOG = 'scan.log';
42 +
41 43 /**
44 + * Records whether a scan has been started on this installation.
45 + *
46 + * @var string
47 + */
48 + public const FIRST_SCAN_STARTED = 'wp_defender_first_scan_started';
49 +
50 + /**
51 + * Default number of issue items per page on the Scan Issues UI.
52 + */
53 + public const DEFAULT_PER_PAGE = 10;
54 +
55 + /**
42 56 * The slug identifier for this controller.
43 57 *
44 58 * @var string
45 59 */
@@ -57,9 +71,8 @@
57 71 *
58 72 * @var Scan_Component
59 73 */
60 74 protected $service;
61 -
62 75 /**
63 76 * Quarantine controller.
64 77 *
65 78 * @var Quarantine
@@ -66,13 +79,13 @@
66 79 */
67 80 private $quarantine_controller;
68 81
69 82 /**
70 - * Indicates whether the current installation is a pro version.
83 + * Is the Malware Report option unlocked?
71 84 *
72 85 * @var bool
73 86 */
74 - private $is_pro;
87 + private $is_unlocked;
75 88
76 89 /**
77 90 * Initializes the model and service, registers routes, and sets up scheduled events if the model is active.
78 91 */
@@ -83,15 +96,13 @@
83 96 array( $this, 'main_view' ),
84 97 $this->parent_slug
85 98 );
86 99
87 - $this->model = new Scan_Settings();
88 - $this->service = wd_di()->get( Scan_Component::class );
89 - $this->is_pro = wd_di()->get( WPMUDEV::class )->is_pro();
100 + $this->model = wd_di()->get( Scan_Settings::class );
101 + $this->service = wd_di()->get( Scan_Component::class );
102 + $this->quarantine_controller = wd_di()->get( Quarantine::class );
90 103
91 - if ( class_exists( 'WP_Defender\Controller\Quarantine' ) ) {
92 - $this->quarantine_controller = wd_di()->get( Quarantine::class );
93 - }
104 + $this->is_unlocked = wd_di()->get( WPMUDEV::class )->is_pro();
94 105
95 106 $this->register_routes();
96 107 add_action( 'defender_enqueue_assets', array( $this, 'enqueue_assets' ) );
97 108 add_action( 'wp_ajax_defender_process_scan', array( $this, 'process' ) );
@@ -105,9 +116,9 @@
105 116 if (
106 117 is_admin() &&
107 118 'plugins.php' === $pagenow &&
108 119 apply_filters( 'wd_display_vulnerability_warnings', true ) &&
109 - $this->is_pro
120 + wd_di()->get( WPMUDEV::class )->is_apikey_available()
110 121 ) {
111 122 $this->service->display_vulnerability_warnings();
112 123 }
113 124
@@ -136,9 +147,9 @@
136 147 *
137 148 * @return string The title of the page.
138 149 */
139 150 public function get_title(): string {
140 - return esc_html__( 'Malware Scanning', 'defender-security' );
151 + return esc_html__( 'Issues', 'defender-security' );
141 152 }
142 153
143 154 /**
144 155 * Clean up data after core updating.
@@ -151,15 +162,32 @@
151 162
152 163 /**
153 164 * Start a scan.
154 165 *
166 + * @param Request $request Request object.
167 + *
155 168 * @return Response
156 169 * @defender_route
157 170 * @defender_redirect
158 171 */
159 - public function start(): Response {
172 + public function start( Request $request ): Response {
173 + $data = $request->get_data(
174 + array(
175 + 'scan_type' => array(
176 + 'type' => 'string',
177 + 'sanitize' => 'sanitize_key',
178 + ),
179 + )
180 + );
181 + $scan_type = in_array( $data['scan_type'] ?? '', array( 'deep', 'malware' ), true )
182 + ? $data['scan_type']
183 + : 'malware';
184 +
160 185 $model = Model_Scan::create();
161 186 if ( is_object( $model ) && ! is_wp_error( $model ) ) {
187 + update_site_option( self::FIRST_SCAN_STARTED, '1' );
188 + set_transient( 'defender_scan_triggered_by_' . $model->id, get_current_user_id(), HOUR_IN_SECONDS );
189 + Model_Scan::set_scan_type( $scan_type );
162 190 $this->log( 'Initial ping self', self::SCAN_LOG );
163 191 $this->run_scan_mechanisms_from( 'scan' );
164 192
165 193 return new Response(
@@ -167,8 +195,9 @@
167 195 array(
168 196 'status' => $model->status,
169 197 'status_text' => $model->get_status_text(),
170 198 'percent' => 0,
199 + 'scan_type' => $scan_type,
171 200 )
172 201 );
173 202 }
174 203
@@ -188,16 +217,14 @@
188 217 * @is_public
189 218 */
190 219 public function process() {
191 220 $lock_filename = $this->service->get_lock_filename();
192 - if ( $this->service->has_lock( $lock_filename ) ) {
221 + if ( ! $this->service->try_create_lock( $lock_filename ) ) {
193 222 $this->log( 'Fallback as already a process is running', self::SCAN_LOG );
194 223
195 224 return;
196 225 }
197 226
198 - // This creates file lock, for make sure only 1 process run as a time.
199 - $this->service->create_lock( $lock_filename );
200 227 // Check if the ping is from self or not.
201 228 $ret = $this->service->process();
202 229 $this->log( 'process done, queue for next', self::SCAN_LOG );
203 230 if ( false === $ret ) {
@@ -218,14 +245,16 @@
218 245 * @defender_route
219 246 * @defender_redirect
220 247 */
221 248 public function status(): Response {
249 + $scan_type = Model_Scan::get_scan_type();
222 250 $idle_scan = wd_di()->get( Model_Scan::class )->get_idle();
223 251
224 252 if ( is_object( $idle_scan ) ) {
225 253 $this->service->update_idle_scan_status();
254 + $response = $this->get_status_response_data( $idle_scan, $scan_type );
226 255
227 - return new Response( false, $idle_scan->to_array() );
256 + return new Response( true, $response );
228 257 }
229 258
230 259 $checksum_issue = get_site_option( Core_Integrity::ISSUE_CHECKSUMS, 'false' );
231 260 $checksum_scan = Model_Scan::get_core_check();
@@ -230,21 +259,33 @@
230 259 $checksum_issue = get_site_option( Core_Integrity::ISSUE_CHECKSUMS, 'false' );
231 260 $checksum_scan = Model_Scan::get_core_check();
232 261 if ( 'false' !== $checksum_issue && is_object( $checksum_scan ) ) {
233 262 $this->service->update_idle_scan_status_by_checksum_issue( $checksum_scan );
263 + $response = $this->get_status_response_data( $checksum_scan, $scan_type );
234 264
235 - return new Response( false, $checksum_scan->to_array() );
265 + return new Response( true, $response );
236 266 }
237 267
238 268 $scan = Model_Scan::get_active();
239 269 if ( is_object( $scan ) ) {
270 + $response = $this->get_status_response_data( $scan, $scan_type );
240 271
241 - return new Response( false, $scan->to_array() );
272 + return new Response( true, $response );
242 273 }
274 +
243 275 $scan = Model_Scan::get_last();
244 276 if ( is_object( $scan ) && ! is_wp_error( $scan ) ) {
245 - $response = $scan->to_array();
246 - $response['message'] = __( 'Malware scan completed successfully!', 'defender-security' );
277 + $response = array_merge( $this->get_status_response_data( $scan, $scan_type ), $this->get_last_scan_time_data( $scan ) );
278 + $response['message'] = __( 'Malware scan completed successfully!', 'defender-security' );
279 + $response['scan_type'] = $scan_type;
280 + if ( 'deep' === $scan_type ) {
281 + $security_tweaks = wd_di()->get( \WP_Defender\Controller\Security_Tweaks::class )->dashboard_widget();
282 + $response['hardening_count'] = (int) ( $security_tweaks['summary']['issues_count'] ?? 0 );
283 + }
284 + if ( isset( $this->quarantine_controller ) ) {
285 + $response['quarantine'] = $this->quarantine_controller->data_frontend()['list'] ?? array();
286 + }
287 +
247 288 return new Response( true, $response );
248 289 }
249 290
250 291 return new Response(
@@ -255,8 +296,24 @@
255 296 );
256 297 }
257 298
258 299 /**
300 + * Build the compatible status payload and consume its queued messages.
301 + *
302 + * @param Model_Scan $scan Scan model used to build the status payload.
303 + * @param string $scan_type Current scan type.
304 + */
305 + private function get_status_response_data( Model_Scan $scan, string $scan_type ): array {
306 + $response = $scan->to_array();
307 + $response['status_text'] = $response['status_text'] ?? $scan->get_status_text();
308 + $response['percent'] = $response['percent'] ?? $scan->percent;
309 + $response['scan_type'] = $scan_type;
310 + $response['status_messages'] = $scan->drain_status_messages();
311 +
312 + return $response;
313 + }
314 +
315 + /**
259 316 * Cancel current scan.
260 317 *
261 318 * @return Response
262 319 * @defender_route
@@ -264,8 +321,9 @@
264 321 */
265 322 public function cancel(): Response {
266 323 $component = wd_di()->get( Scan_Component::class );
267 324 $component->cancel_a_scan();
325 + Model_Scan::clear_scan_type();
268 326 $last = Model_Scan::get_last();
269 327 if ( is_object( $last ) && ! is_wp_error( $last ) ) {
270 328 $last = $last->to_array();
271 329 }
@@ -376,9 +434,9 @@
376 434 $intention,
377 435 $allowed_intentions,
378 436 true
379 437 ) ) {
380 - wp_die();
438 + return new Response( false, array() );
381 439 }
382 440
383 441 $scan = Model_Scan::get_last();
384 442 if ( $scan instanceof Model_Scan ) {
@@ -383,12 +441,12 @@
383 441 $scan = Model_Scan::get_last();
384 442 if ( $scan instanceof Model_Scan ) {
385 443 $item = $scan->get_issue( $id );
386 444 if ( is_object( $item ) && $item->has_method( $intention ) ) {
387 - if ( 'quarantine' === $intention ) {
445 + if ( 'resolve' === $intention ) {
446 + $result = $item->resolve();
447 + } elseif ( 'quarantine' === $intention ) {
388 448 $result = $item->quarantine( $data['parent_action'], $item->owner );
389 - } elseif ( 'resolve' === $intention ) {
390 - $result = $item->resolve();
391 449 } elseif ( 'delete' === $intention ) {
392 450 $result = $item->delete();
393 451 } elseif ( 'ignore' === $intention ) {
394 452 $result = $item->ignore();
@@ -430,8 +488,12 @@
430 488
431 489 if ( $scan instanceof Model_Scan ) {
432 490 $result['scan'] = $scan->to_array();
433 491
492 + if ( 'quarantine' === $intention && isset( $this->quarantine_controller ) ) {
493 + $result['quarantine'] = $this->quarantine_controller->data_frontend()['list'] ?? array();
494 + }
495 +
434 496 $success = true;
435 497 if ( isset( $result['success'] ) && false === $result['success'] ) {
436 498 $success = false;
437 499 }
@@ -551,18 +613,15 @@
551 613 * @defender_route
552 614 */
553 615 public function save_settings( Request $request ): Response {
554 616 $data = $request->get_data_by_model( $this->model );
555 - // Case#1: enable all child options, if parent and all child options are disabled, so that there is no notice when saving.
556 - if (
557 - ! $data['integrity_check']
558 - && ! $data['check_core']
559 - && ! $data['check_plugins']
560 - ) {
561 - $data['check_core'] = true;
562 - $data['check_plugins'] = true;
617 + // Prepare for the state's change.
618 + $old_integrity_check_state = $this->model->integrity_check;
619 + // Case#1: inherit the parent's state to nested options.
620 + if ( $old_integrity_check_state !== $data['integrity_check'] ) {
621 + $data['check_core'] = $data['integrity_check'];
622 + $data['check_plugins'] = $data['integrity_check'];
563 623 }
564 -
565 624 // Case#2: Suspicious code is activated BUT File change detection is deactivated then show the notice.
566 625 if ( $data['scan_malware'] && ! $data['integrity_check'] ) {
567 626 $response = array(
568 627 'type_notice' => 'info',
@@ -578,36 +637,17 @@
578 637 '</strong>'
579 638 ),
580 639 );
581 640 } else {
582 - // Prepare response message for usual successful case.
583 641 $response = array(
584 642 'message' => esc_html__( 'Your settings have been updated.', 'defender-security' ),
585 643 'auto_close' => true,
586 644 );
587 645 }
588 - // Additional cases are in the Scan model.
589 - $report_change = false;
590 - // If 'Scheduled Scanning' is checked then need to change Malware_Report.
591 - if ( true === $data['scheduled_scanning'] ) {
592 - $report = new Malware_Report();
593 - $report_change = true;
594 - $report->frequency = $data['frequency'];
595 - $report->day = $data['day'];
596 - $report->day_n = (int) $data['day_n'];
597 - $report->time = $data['time'];
598 - // Disable 'Scheduled Scanning'.
599 - } elseif ( true === $this->model->scheduled_scanning && false === $data['scheduled_scanning'] ) {
600 - $report = new Malware_Report();
601 - $report_change = true;
602 - $report->status = \WP_Defender\Model\Notification::STATUS_DISABLED;
603 - }
604 -
605 646 $before_import_schedule = $this->model->quarantine_expire_schedule;
606 647
607 648 $this->model->import( $data );
608 649 if ( $this->model->validate() ) {
609 -
610 650 if ( class_exists( 'WP_Defender\Component\Quarantine' ) ) {
611 651 $quarantine_component = wd_di()->get( Quarantine_Component::class );
612 652 $quarantine_component->reschedule_file_expiry_cron(
613 653 $before_import_schedule,
@@ -614,14 +654,9 @@
614 654 $data['quarantine_expire_schedule']
615 655 );
616 656 }
617 657
618 - // Todo: need to disable Malware_Notification & Malware_Report if all scan settings are deactivated?
619 658 $this->model->save();
620 - // Save Report's changes.
621 - if ( $report_change ) {
622 - $report->save();
623 - }
624 659 Config_Hub_Helper::set_clear_active_flag();
625 660
626 661 return new Response(
627 662 true,
@@ -655,9 +690,9 @@
655 690 'type' => 'string',
656 691 'sanitize' => 'sanitize_text_field',
657 692 ),
658 693 'type' => array(
659 - 'type' => 'string',
694 + 'type' => 'array',
660 695 'sanitize' => 'sanitize_text_field',
661 696 ),
662 697 'per_page' => array(
663 698 'type' => 'string',
@@ -676,30 +711,167 @@
676 711 if ( ! $v->validate() ) {
677 712 return new Response(
678 713 false,
679 714 array(
680 - 'message' => '',
715 + 'message' => esc_html__( 'Wrong scan issue data.', 'defender-security' ),
681 716 )
682 717 );
683 718 }
684 719
685 720 $scan = Model_Scan::get_last();
686 - $issues = $scan->to_array( $data['per_page'], $data['paged'], $data['type'] );
721 + $issues = $scan->to_array( $data['per_page'], $data['paged'], $this->normalize_issue_types( $data['type'] ), $data['scenario'] );
687 722
688 - return new Response(
689 - true,
690 - array(
691 - 'issue' => $issues['issues_items'],
692 - 'ignored' => $issues['ignored_items'],
693 - 'paging' => $issues['paging'],
694 - 'count' => $issues['count'],
695 - )
723 + $response = array(
724 + 'issue' => $issues['issues_items'],
725 + 'ignored' => $issues['ignored_items'],
726 + 'paging' => $issues['paging'],
727 + 'count' => $issues['count'],
696 728 );
729 +
730 + if ( class_exists( 'WP_Defender\Controller\Quarantine' ) ) {
731 + $response['quarantine'] = $this->quarantine_controller->data_frontend()['list'] ?? array();
732 + }
733 +
734 + return new Response( true, $response );
697 735 }
698 736
699 737 /**
700 - * Render main page.
738 + * Normalize issue type filters from the legacy and redesign payloads.
701 739 *
740 + * @param array|string $types Requested issue type(s).
741 + *
742 + * @return array|string
743 + */
744 + private function normalize_issue_types( $types ) {
745 + $type_aliases = array(
746 + 'core' => Scan_Item::TYPE_INTEGRITY,
747 + 'plugin' => Scan_Item::TYPE_PLUGIN_CHECK,
748 + 'suspicious' => Scan_Item::TYPE_SUSPICIOUS,
749 + 'known_vulnerability' => Scan_Item::TYPE_VULNERABILITY,
750 + 'plugin_closed' => Scan_Item::TYPE_PLUGIN_CLOSED,
751 + 'plugin_outdated' => Scan_Item::TYPE_PLUGIN_OUTDATED,
752 + );
753 +
754 + $types = is_array( $types ) ? $types : array( $types );
755 + $types = array_filter(
756 + array_map(
757 + static function ( $type ) use ( $type_aliases ) {
758 + return $type_aliases[ $type ] ?? $type;
759 + },
760 + $types
761 + ),
762 + 'boolval'
763 + );
764 + $types = array_values( array_unique( $types ) );
765 +
766 + if ( 1 === count( $types ) ) {
767 + return $types[0];
768 + }
769 +
770 + return $types;
771 + }
772 +
773 + /**
774 + * Get relative and exact display times for the last completed scan.
775 + *
776 + * @param Model_Scan|null $last Last completed scan.
777 + *
778 + * @return array
779 + */
780 + private function get_last_scan_time_data( $last ): array {
781 + if ( ! is_object( $last ) || ! isset( $last->date_start ) || '' === $last->date_start ) {
782 + return array(
783 + 'last_scan' => '',
784 + 'last_scan_time' => '',
785 + );
786 + }
787 +
788 + $last_scan_timestamp = strtotime( $last->date_start . ' UTC' );
789 + $time_difference = time() - $last_scan_timestamp;
790 + $data = array(
791 + 'last_scan' => sprintf(
792 + /* translators: %s: human-readable time difference, e.g. "5 minutes ago" */
793 + __( 'Scanned %s ago', 'defender-security' ),
794 + human_time_diff( $last_scan_timestamp )
795 + ),
796 + );
797 +
798 + if ( $time_difference < DAY_IN_SECONDS ) {
799 + $data['last_scan_time'] = wp_date( 'g:i A', $last_scan_timestamp );
800 + } elseif ( $time_difference < YEAR_IN_SECONDS ) {
801 + $data['last_scan_time'] = wp_date( 'D, j M g:i A', $last_scan_timestamp );
802 + } else {
803 + $data['last_scan_time'] = wp_date( 'j M Y, g:i A', $last_scan_timestamp );
804 + }
805 +
806 + return $data;
807 + }
808 +
809 + /**
810 + * Returns scan result data for the frontend on page load.
811 + *
812 + * @return array
813 + */
814 + public function get_initial_scan_data(): array {
815 + $scan = Model_Scan::get_active();
816 + $last = Model_Scan::get_last();
817 + $per_page = self::DEFAULT_PER_PAGE;
818 + $paged = 1;
819 +
820 + if ( ! is_object( $scan ) && ! is_object( $last ) ) {
821 + $scan_data = null;
822 + } elseif ( is_object( $scan ) && is_object( $last ) ) {
823 + // If an active scan exists AND there's a previous completed scan,
824 + // merge the active scan's progress with the last scan's issue data.
825 + // This ensures that during a page refresh while scanning, users still
826 + // see the previous scan results while the new scan is in progress.
827 + $scan_data = $scan->to_array( $per_page, $paged );
828 + $last_data = $last->to_array( $per_page, $paged );
829 + // Preserve previous scan's issue data.
830 + $scan_data['issues_items'] = $last_data['issues_items'] ?? array();
831 + $scan_data['ignored_items'] = $last_data['ignored_items'] ?? array();
832 + $scan_data['count'] = $last_data['count'] ?? array();
833 + $scan_data['paging'] = $last_data['paging'] ?? array();
834 + } elseif ( is_object( $scan ) ) {
835 + $scan_data = $scan->to_array( $per_page, $paged );
836 + } else {
837 + $scan_data = $last->to_array( $per_page, $paged );
838 + }
839 +
840 + $first_scan_started = get_site_option( self::FIRST_SCAN_STARTED, null );
841 + if ( null === $first_scan_started ) {
842 + // Existing installations backward compatibility.
843 + $first_scan_started = is_object( $scan ) || is_object( $last );
844 + } else {
845 + $first_scan_started = '1' === (string) $first_scan_started;
846 + }
847 +
848 + $data = array(
849 + 'scan' => $scan_data,
850 + 'has_first_scan_started' => $first_scan_started,
851 + 'isEnabledScanType' => $this->service->is_any_scan_type_active(),
852 + );
853 +
854 + // Always expose the last completed scan time at the outer level so the
855 + // dashboard can show it even while a new scan is actively running.
856 + $data = array_merge( $data, $this->get_last_scan_time_data( $last ) );
857 +
858 + if ( isset( $this->quarantine_controller ) ) {
859 + $data['quarantine'] = array(
860 + 'list' => $this->quarantine_controller->data_frontend()['list'] ?? array(),
861 + );
862 + }
863 + // Display Rate notice. Without the rating's type.
864 + $data['isRatingDisplayed'] = defender_is_wp_org_version()
865 + && is_array( $scan_data ) && isset( $data['scan']['issues_items'] )
866 + && Rate_Component::is_displayed_in_redesigned_version( count( $data['scan']['issues_items'] ) );
867 +
868 + return array( 'scan' => $data );
869 + }
870 +
871 + /**
872 + * Render the main page.
873 + *
702 874 * @return void
703 875 */
704 876 public function main_view(): void {
705 877 $this->render( 'main' );
@@ -712,11 +884,58 @@
712 884 public function enqueue_assets() {
713 885 if ( ! $this->is_page_active() ) {
714 886 return;
715 887 }
716 - wp_localize_script( 'def-scan', 'scan', $this->data_frontend() );
717 - wp_enqueue_script( 'def-scan' );
718 - wp_enqueue_script( 'clipboard' );
888 +
889 + $handle = 'defender-ui-scan';
890 + wp_enqueue_script(
891 + $handle,
892 + WP_DEFENDER_BASE_URL . 'assets/js/scan-ui.js',
893 + array( 'def-vue', 'def-manifest', 'def-core-ui', 'defender', 'wp-i18n' ),
894 + DEFENDER_VERSION,
895 + true
896 + );
897 + wp_set_script_translations( $handle, 'wpdef' );
898 +
899 + $scan_routes_data = $this->dump_routes_and_nonces();
900 + $quarantine_routes_data = $this->quarantine_controller->dump_routes_and_nonces();
901 + if ( defender_is_wp_org_version() ) {
902 + $rate_routes_nonces = wd_di()->get( \WP_Defender\Controller\Rate::class )->dump_routes_and_nonces();
903 + $rate_routes = $rate_routes_nonces['routes'];
904 + $rate_nonces = $rate_routes_nonces['nonces'];
905 + } else {
906 + $rate_routes = array();
907 + $rate_nonces = array();
908 + }
909 +
910 + wp_localize_script(
911 + $handle,
912 + 'defenderUIData',
913 + array_merge(
914 + $this->get_shared_data(),
915 + array(
916 + 'routes' => array_merge(
917 + $scan_routes_data['routes'],
918 + $quarantine_routes_data['routes'],
919 + $rate_routes
920 + ),
921 + 'nonces' => array_merge(
922 + $scan_routes_data['nonces'],
923 + $quarantine_routes_data['nonces'],
924 + $rate_nonces
925 + ),
926 + ),
927 + $this->get_initial_scan_data()
928 + )
929 + );
930 +
931 + wp_enqueue_style(
932 + $handle,
933 + WP_DEFENDER_BASE_URL . 'assets/css/core-ui.css',
934 + array(),
935 + DEFENDER_VERSION
936 + );
937 +
719 938 $this->enqueue_main_assets();
720 939 }
721 940
722 941 /**
@@ -755,9 +974,12 @@
755 974 /**
756 975 * Delete all the data & the cache.
757 976 */
758 977 public function remove_data(): void {
978 + delete_site_option( self::FIRST_SCAN_STARTED );
759 979 delete_site_option( Model_Scan::IGNORE_INDEXER );
980 + delete_site_option( Model_Scan::OPTION_SCAN_TYPE );
981 + Model_Scan::clear_all_status_messages();
760 982 delete_site_option( Core_Integrity::ISSUE_CHECKSUMS );
761 983 delete_site_transient( Plugin_Integrity::$org_slugs );
762 984 delete_site_transient( Plugin_Integrity::$org_responses );
763 985 }
@@ -776,61 +998,23 @@
776 998 $scan = null;
777 999 } else {
778 1000 $scan = is_object( $scan ) ? $scan->to_array( $per_page, $paged ) : $last->to_array( $per_page, $paged );
779 1001 }
780 - $settings = new Scan_Settings();
781 - $report = wd_di()->get( Malware_Report::class );
782 - $report_text = esc_html__( 'Automatic scans are disabled', 'defender-security' );
783 - if ( $settings->scheduled_scanning && isset( $settings->frequency ) ) {
784 - $report_text = sprintf(
785 - /* translators: 1. Line break tag. 2. Frequency value. */
786 - esc_html__( 'Automatic scans are %1$srunning %2$s', 'defender-security' ),
787 - '<br/>',
788 - $settings->frequency
789 - );
790 - }
791 - $misc = array(
792 - 'outdated_period' => \WP_Defender\Behavior\Scan\Abandoned_Plugin::get_outdated_period(),
793 - 'labels' => $settings->labels(),
794 - 'days_of_week' => $this->get_days_of_week(),
795 - 'times_of_day' => $this->get_times(),
796 - );
797 - $misc['timezone_text'] = sprintf(
798 - /* translators: 1. Timezone. 2. Time. */
799 - esc_html__(
800 - 'Your timezone is set to %1$s, so your current time is %2$s.',
801 - 'defender-security'
802 - ),
803 - '<strong>' . wp_timezone_string() . '</strong>',
804 - '<strong>' . wp_date( 'H:i', time() ) . '</strong>'
805 - );
1002 + $settings = new Scan_Settings();
1003 + $report = wd_di()->get( Malware_Report::class );
806 1004
807 - // Todo: add logic for deactivated scan settings. Maybe display some notice.
808 - $data = array(
809 - 'scan' => $scan,
810 - 'settings' => $settings->export(),
811 - 'report' => $report_text,
812 - 'active_tools' => array(
813 - 'integrity_check' => $settings->integrity_check,
814 - 'check_known_vuln' => $settings->check_known_vuln,
815 - 'scan_malware' => $settings->scan_malware,
816 - 'scheduled_scanning' => $settings->scheduled_scanning,
817 - 'check_abandoned_plugin' => $settings->check_abandoned_plugin,
1005 + $scan['isEnabledScanType'] = $this->service->is_any_scan_type_active();
1006 +
1007 + $data = array(
1008 + 'scan' => $scan,
1009 + 'settings' => $settings->export(),
1010 + 'notification' => $report->to_string(),
1011 + 'misc' => array(
1012 + 'labels' => $settings->labels(),
818 1013 ),
819 - 'notification' => $report->to_string(),
820 - 'next_run' => $report->get_next_run_as_string(),
821 - 'misc' => $misc,
822 - 'upsell' => array(
823 - 'scan' => $this->get_scan_upsell( 'scan' ),
824 - ),
825 - 'hub_connector' => wd_di()->get( Hub_Connector::class )->data_frontend(),
826 - 'antibot' => wd_di()->get( Antibot_Global_Firewall::class )->data_frontend(),
827 1014 );
1015 + $data['quarantine'] = $this->quarantine_controller->data_frontend();
828 1016
829 - if ( class_exists( 'WP_Defender\Controller\Quarantine' ) ) {
830 - $data['quarantine'] = $this->quarantine_controller->data_frontend();
831 - }
832 -
833 1017 return array_merge( $data, $this->dump_routes_and_nonces() );
834 1018 }
835 1019
836 1020 /**
@@ -855,30 +1039,8 @@
855 1039 }
856 1040 }
857 1041
858 1042 /**
859 - * Checks if any scan is active.
860 - *
861 - * @param bool $is_pro Indicates if the product is a pro version.
862 - *
863 - * @return bool True if any scan is active, false otherwise.
864 - */
865 - private function is_any_active( bool $is_pro ): bool {
866 - $settings = new Scan_Settings();
867 - $file_change_check = $settings->is_checked_any_file_change_types();
868 -
869 - if ( $is_pro ) {
870 - // Pro version. Check all parent types.
871 - return $file_change_check || $settings->check_known_vuln || $settings->scan_malware;
872 - } else {
873 - // Free version:
874 - // Check the 'File change detection' type because only it's available with nested types.
875 - // Check the Abandoned plugin type.
876 - return $file_change_check || $settings->check_abandoned_plugin;
877 - }
878 - }
879 -
880 - /**
881 1043 * Exports strings.
882 1044 *
883 1045 * @return array An array of strings.
884 1046 */
@@ -883,48 +1045,37 @@
883 1045 * @return array An array of strings.
884 1046 */
885 1047 public function export_strings(): array {
886 1048 $strings = array();
887 - if ( $this->is_any_active( $this->is_pro ) ) {
1049 + if ( $this->service->is_any_scan_type_active() ) {
888 1050 $strings[] = esc_html__( 'Active', 'defender-security' );
889 1051 } else {
890 1052 $strings[] = esc_html__( 'Inactive', 'defender-security' );
891 1053 }
892 1054
893 - $scan_report = new Malware_Report();
894 1055 $scan_notification = new Malware_Notification();
895 1056 if ( 'enabled' === $scan_notification->status ) {
896 1057 $strings[] = esc_html__( 'Email notifications active', 'defender-security' );
897 1058 }
898 - if ( $this->is_pro && 'enabled' === $scan_report->status ) {
899 1059 $strings[] = sprintf(
900 - /* translators: %s: Frequency value. */
901 - esc_html__( 'Email reports sending %s', 'defender-security' ),
902 - $scan_report->frequency
903 - );
904 - } elseif ( ! $this->is_pro ) {
905 - $strings[] = sprintf(
906 1060 /* translators: %s: Html for Pro-tag. */
907 - esc_html__( 'Email report inactive %s', 'defender-security' ),
1061 + esc_html__( 'Scheduled scan inactive %s', 'defender-security' ),
908 1062 '<span class="sui-tag sui-tag-pro">Pro</span>'
909 1063 );
910 - }
911 1064
912 1065 return $strings;
913 1066 }
914 1067
915 1068 /**
916 - * Generates configuration strings based on the provided configuration and
917 - * whether the product is a pro version.
1069 + * Generates configuration strings based on the provided configuration.
918 1070 *
919 1071 * @param array $config Configuration data.
920 - * @param bool $is_pro Indicates if the product is a pro version.
921 1072 *
922 1073 * @return array Returns an array of configuration strings.
923 1074 */
924 - public function config_strings( array $config, bool $is_pro ): array {
1075 + public function config_strings( array $config ): array {
925 1076 $strings = array();
926 - $strings[] = $this->service->is_any_scan_active( $config )
1077 + $strings[] = $this->service->check_scan_active_by( $config )
927 1078 ? esc_html__( 'Active', 'defender-security' )
928 1079 : esc_html__( 'Inactive', 'defender-security' );
929 1080
930 1081 if ( 'enabled' === $config['notification'] ) {
@@ -929,18 +1080,13 @@
929 1080
930 1081 if ( 'enabled' === $config['notification'] ) {
931 1082 $strings[] = esc_html__( 'Email notifications active', 'defender-security' );
932 1083 }
933 - if ( $is_pro && 'enabled' === $config['report'] ) {
1084 + // No Pro membership and No hosted site.
1085 + if ( ! $this->is_unlocked ) {
934 1086 $strings[] = sprintf(
935 - /* translators: %s: Frequency value. */
936 - esc_html__( 'Email reports sending %s', 'defender-security' ),
937 - $config['frequency']
938 - );
939 - } elseif ( ! $is_pro ) {
940 - $strings[] = sprintf(
941 1087 /* translators: %s: Html for Pro-tag. */
942 - esc_html__( 'Email report inactive %s', 'defender-security' ),
1088 + esc_html__( 'Scheduled scan inactive %s', 'defender-security' ),
943 1089 '<span class="sui-tag sui-tag-pro">Pro</span>'
944 1090 );
945 1091 }
946 1092