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/class-scan-item.php +47 -7 5.4.0 → 6.3.0 View file →
@@ -9,8 +9,9 @@
9 9
10 10 use WP_Defender\DB;
11 11 use WP_Defender\Behavior\Scan_Item\Vuln_Result;
12 12 use WP_Defender\Behavior\Scan_Item\Malware_Result;
13 +use WP_Defender\Behavior\Scan_Item\Abandoned_Result;
13 14
14 15 /**
15 16 * Model for scan item table.
16 17 */
@@ -19,8 +20,10 @@
19 20 // For 'File change detection' option.
20 21 public const TYPE_INTEGRITY = 'core_integrity', TYPE_PLUGIN_CHECK = 'plugin_integrity';
21 22 // For 'Known vulnerabilities' and 'Suspicious code' options.
22 23 public const TYPE_VULNERABILITY = 'vulnerability', TYPE_SUSPICIOUS = 'malware';
24 + // For 'Abandoned' option.
25 + public const TYPE_PLUGIN_CLOSED = 'plugin_closed', TYPE_PLUGIN_OUTDATED = 'plugin_outdated';
23 26 // Different statuses.
24 27 public const STATUS_ACTIVE = 'active', STATUS_IGNORE = 'ignore';
25 28
26 29 /**
@@ -71,18 +74,23 @@
71 74 *
72 75 * @param int $parent_id The primary key of the scan table.
73 76 * @param string $status Active or ignore status of scan item(s).
74 77 *
75 - * @return array Return array of group and all total.
78 + * @return array Return array of groups and all total.
76 79 */
77 - public function get_types_total( $parent_id, $status ) {
80 + public function get_types_total( $parent_id, $status ): array {
78 81 global $wpdb;
79 82
83 + $types = self::get_all_scan_types();
84 + $placeholders = implode( ', ', array_fill( 0, count( $types ), '%s' ) );
85 +
80 86 $records = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
81 - $wpdb->prepare(
82 - "SELECT IFNULL(`type`, 'all') as `item_type`, count(*) as `type_total` FROM {$wpdb->base_prefix}defender_scan_item WHERE `parent_id` = %d AND `status` = %s Group BY `type` WITH ROLLUP",
83 - $parent_id,
84 - $status
87 + $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
88 + "SELECT IFNULL(`type`, 'all') as `item_type`, count(*) as `type_total`" .
89 + " FROM {$wpdb->base_prefix}defender_scan_item" .
90 + " WHERE `parent_id` = %d AND `status` = %s AND `type` IN ($placeholders)" . // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
91 + ' Group BY `type` WITH ROLLUP',
92 + array_merge( array( $parent_id, $status ), $types )
85 93 )
86 94 );
87 95
88 96 $results = array();
@@ -115,10 +123,10 @@
115 123 * @return void
116 124 */
117 125 public function import( $data ): void {
118 126 parent::import( $data );
127 + // Add behaviors.
119 128 switch ( $this->type ) {
120 - // Add other behaviors here.
121 129 case self::TYPE_SUSPICIOUS:
122 130 $this->attach_behavior( Malware_Result::class, Malware_Result::class );
123 131 break;
124 132 case self::TYPE_VULNERABILITY:
@@ -123,9 +131,41 @@
123 131 break;
124 132 case self::TYPE_VULNERABILITY:
125 133 $this->attach_behavior( Vuln_Result::class, Vuln_Result::class );
126 134 break;
135 + case self::TYPE_PLUGIN_CLOSED:
136 + case self::TYPE_PLUGIN_OUTDATED:
137 + $this->attach_behavior( Abandoned_Result::class, Abandoned_Result::class );
138 + break;
127 139 default:
128 140 break;
129 141 }
142 + }
143 +
144 + /**
145 + * Get all Scan types.
146 + *
147 + * @return array
148 + */
149 + public static function get_all_scan_types(): array {
150 + return array(
151 + self::TYPE_VULNERABILITY,
152 + self::TYPE_SUSPICIOUS,
153 + self::TYPE_INTEGRITY,
154 + self::TYPE_PLUGIN_CHECK,
155 + self::TYPE_PLUGIN_CLOSED,
156 + self::TYPE_PLUGIN_OUTDATED,
157 + );
158 + }
159 +
160 + /**
161 + * Get all scan statuses.
162 + *
163 + * @return array
164 + */
165 + public static function get_all_scan_statuses(): array {
166 + return array(
167 + self::STATUS_ACTIVE,
168 + self::STATUS_IGNORE,
169 + );
130 170 }
131 171 }