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/model/setting/class-scan.php +48 -48 5.3.1 → 6.3.0 View file →
@@ -6,12 +6,9 @@
6 6 */
7 7
8 8 namespace WP_Defender\Model\Setting;
9 9
10 -use DateTime;
11 -use Exception;
12 10 use Calotes\Model\Setting;
13 -use function wp_timezone;
14 11
15 12 /**
16 13 * Model for scan settings.
17 14 */
@@ -86,9 +83,9 @@
86 83 * @var string
87 84 * @defender_property
88 85 * @rule in[daily,weekly,monthly]
89 86 */
90 - public $frequency;
87 + public $frequency = 'weekly';
91 88
92 89 /**
93 90 * The day of scheduled scan.
94 91 *
@@ -95,18 +92,17 @@
95 92 * @var string
96 93 * @defender_property
97 94 * @sanitize_text_field
98 95 */
99 - public $day;
96 + public $day = '';
100 97
101 98 /**
102 99 * This is for when user select scheduled scan as monthly, we will have the day number, instead of text.
103 100 *
104 101 * @var int
105 - * @sanitize_text_field
106 102 * @defender_property
107 103 */
108 - public $day_n;
104 + public int $day_n = 1;
109 105
110 106 /**
111 107 * Same as $day.
112 108 *
@@ -113,9 +109,9 @@
113 109 * @var string
114 110 * @defender_property
115 111 * @sanitize_text_field
116 112 */
117 - public $time;
113 + public $time = '';
118 114
119 115 /**
120 116 * Quarantine file deletion/expiration cron schedule.
121 117 *
@@ -125,8 +121,16 @@
125 121 */
126 122 public $quarantine_expire_schedule = 'thirty_days';
127 123
128 124 /**
125 + * Enable Abandoned or outdated plugins.
126 + *
127 + * @defender_property
128 + * @var bool
129 + */
130 + public $check_abandoned_plugin = true;
131 +
132 + /**
129 133 * Define settings labels.
130 134 *
131 135 * @return array
132 136 */
@@ -131,19 +135,20 @@
131 135 * @return array
132 136 */
133 137 public function labels(): array {
134 138 return array(
135 - 'integrity_check' => esc_html__( 'File change detection', 'defender-security' ),
136 - 'check_core' => esc_html__( 'Scan core files', 'defender-security' ),
137 - 'check_plugins' => esc_html__( 'Scan plugin files', 'defender-security' ),
138 - 'check_known_vuln' => esc_html__( 'Known vulnerabilities', 'defender-security' ),
139 - 'scan_malware' => esc_html__( 'Suspicious Code', 'defender-security' ),
140 - 'filesize' => esc_html__( 'Max included file size', 'defender-security' ),
141 - 'scheduled_scanning' => esc_html__( 'Scheduled Scanning', 'defender-security' ),
142 - 'frequency' => esc_html__( 'Frequency', 'defender-security' ),
143 - 'day' => esc_html__( 'Day of the week', 'defender-security' ),
144 - 'day_n' => esc_html__( 'Day of the month', 'defender-security' ),
145 - 'time' => esc_html__( 'Time of day', 'defender-security' ),
139 + 'integrity_check' => esc_html__( 'File change detection', 'defender-security' ),
140 + 'check_core' => esc_html__( 'Scan core files', 'defender-security' ),
141 + 'check_plugins' => esc_html__( 'Scan plugin files', 'defender-security' ),
142 + 'check_abandoned_plugin' => esc_html__( 'Outdated & removed plugins', 'defender-security' ),
143 + 'check_known_vuln' => esc_html__( 'Known vulnerabilities', 'defender-security' ),
144 + 'scan_malware' => esc_html__( 'Suspicious code', 'defender-security' ),
145 + 'filesize' => esc_html__( 'Max included file size', 'defender-security' ),
146 + 'scheduled_scanning' => esc_html__( 'Scheduled Scanning', 'defender-security' ),
147 + 'frequency' => esc_html__( 'Frequency', 'defender-security' ),
148 + 'day' => esc_html__( 'Day of the week', 'defender-security' ),
149 + 'day_n' => esc_html__( 'Day of the month', 'defender-security' ),
150 + 'time' => esc_html__( 'Time of day', 'defender-security' ),
146 151 );
147 152 }
148 153
149 154 /**
@@ -168,9 +173,9 @@
168 173 *
169 174 * @return void
170 175 */
171 176 protected function after_validate(): void {
172 - // Case#1: all child types of File change detection are unchecked BUT parent type is checked.
177 + // Case#1: all child types of File change detection are unchecked BUT the parent type is checked.
173 178 if ( $this->integrity_check && ! $this->check_core && ! $this->check_plugins ) {
174 179 $this->errors[] = sprintf(
175 180 /* translators: %s: File change detection. */
176 181 esc_html__( 'You have not selected a scan type for the %s. Please choose at least one and save the settings again.', 'defender-security' ),
@@ -175,12 +180,10 @@
175 180 /* translators: %s: File change detection. */
176 181 esc_html__( 'You have not selected a scan type for the %s. Please choose at least one and save the settings again.', 'defender-security' ),
177 182 '<strong>' . esc_html__( 'File change detection', 'defender-security' ) . '</strong>'
178 183 );
179 - // Case#2: all scan types are unchecked and Scheduled Scanning is checked.
180 - } elseif ( ! $this->integrity_check && ! $this->check_known_vuln && ! $this->scan_malware
181 - && $this->scheduled_scanning
182 - ) {
184 + // Case#2: all scan types are unchecked.
185 + } elseif ( ! $this->is_enabled_any_scan_type() ) {
183 186 $this->errors[] = esc_html__(
184 187 'You have not selected a scan type. Please enable at least one scan type and save the settings again.',
185 188 'defender-security'
186 189 );
@@ -187,35 +190,32 @@
187 190 }
188 191 }
189 192
190 193 /**
191 - * Initializes the object by setting default values for the frequency, day, day_n, and time properties based on the
192 - * current day and time.
194 + * Initializes the object by setting default values.
193 195 *
194 196 * @return void
195 - * @throws Exception Emits Exception in case of an error.
196 - * @since 4.7.1 Implement Dynamic Scan Scheduling to avoid event spikes on MP.
197 197 */
198 198 protected function before_load(): void {
199 - // Get current day and time.
200 - $date = new DateTime( 'now', wp_timezone() );
201 - $result = explode( '--', $date->format( 'l--H--i' ) );
202 - $day = strtolower( $result[0] );
203 - $current_hours = (int) $result[1];
204 - $current_mins = (int) $result[2];
205 - // We have a 30 minute span, so XX:00-15 => XX:00, XX:16-45 => XX:30, XX:46-59 => (XX+1):00.
206 - if ( $current_mins > 15 && $current_mins <= 45 ) {
207 - $mins = '30';
208 - } elseif ( $current_mins >= 0 && $current_mins < 16 ) {
209 - $mins = '00';
210 - } else {
211 - ++$current_hours;
212 - $current_hours >= 24 ? '00' : $current_hours;
213 - $mins = '00';
214 - }
199 + }
215 200
216 - $this->frequency = 'weekly';
217 - $this->day = $day;
218 - $this->day_n = '1';
219 - $this->time = $current_hours . ':' . $mins;
201 + /**
202 + * Is enabled any scan type at least?
203 + *
204 + * @return bool
205 + */
206 + private function is_enabled_any_scan_type(): bool {
207 + return $this->integrity_check
208 + || $this->check_known_vuln
209 + || $this->scan_malware
210 + || $this->check_abandoned_plugin;
211 + }
212 +
213 + /**
214 + * Is enabled Scheduled Scanning?
215 + *
216 + * @return bool
217 + */
218 + public function is_enabled_scheduled_scanning(): bool {
219 + return false;
220 220 }
221 221 }