| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace WP_Defender\Behavior\Scan; |
| 9 | 9 | |
| 10 | 10 | use Calotes\Component\Behavior; |
| 11 | +use WP_Defender\Component\Scan as Scan_Component; | |
| 11 | 12 | use WP_Defender\Controller\Scan as Scan_Controller; |
| 12 | 13 | use WP_Defender\Model\Scan; |
| 13 | 14 | use WP_Defender\Model\Scan_Item; |
| 14 | 15 | use WP_Defender\Traits\IO; |
| @@ -33,9 +34,9 @@ | ||
| 33 | 34 | * Outdated plugin period. |
| 34 | 35 | * |
| 35 | 36 | * @var string |
| 36 | 37 | */ |
| 37 | - private const OUTDATED_PERIOD = '6 months'; | |
| 38 | + private const OUTDATED_PERIOD = '2 years'; | |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * Initialize Scan instance. |
| 41 | 42 | * |
| @@ -49,10 +50,14 @@ | ||
| 49 | 50 | * Get the outdated period of the plugin. |
| 50 | 51 | * |
| 51 | 52 | * @return string |
| 52 | 53 | */ |
| 53 | - public static function get_outdated_period() { | |
| 54 | - return self::OUTDATED_PERIOD; | |
| 54 | + public static function get_outdated_period(): string { | |
| 55 | + // Filter to override outdated threshold period. | |
| 56 | + $period = apply_filters( 'wpdef_scan_outdated_period', self::OUTDATED_PERIOD ); | |
| 57 | + $period = is_string( $period ) ? $period : (string) $period; | |
| 58 | + // If time period is invalid, use the default one. | |
| 59 | + return strtotime( '- ' . $period ) ? $period : self::OUTDATED_PERIOD; | |
| 55 | 60 | } |
| 56 | 61 | |
| 57 | 62 | /** |
| 58 | 63 | * Check if there are abandoned plugins. |
| @@ -60,14 +65,15 @@ | ||
| 60 | 65 | * @return bool |
| 61 | 66 | */ |
| 62 | 67 | public function abandoned_plugin_check(): bool { |
| 63 | 68 | $ignored_issues = $this->get_ignored_issues(); |
| 64 | - $model = $this->scan; | |
| 65 | 69 | |
| 66 | - foreach ( $this->get_plugin_slugs() as $slug ) { | |
| 67 | - if ( is_object( $model ) && $model->is_issue_ignored( $slug ) ) { | |
| 68 | - continue; | |
| 69 | - } | |
| 70 | + $actioned_plugins = get_site_option( Scan_Component::PLUGINS_ACTIONED ); | |
| 71 | + $plugin_list = Scan_Component::are_actioned_plugins( $actioned_plugins ) | |
| 72 | + ? $actioned_plugins | |
| 73 | + : $this->get_plugin_slugs(); | |
| 74 | + | |
| 75 | + foreach ( $plugin_list as $slug => $plugin_data ) { | |
| 70 | 76 | $this->check_abandoned_plugin_by( $slug ); |
| 71 | 77 | } |
| 72 | 78 | |
| 73 | 79 | $this->scan->calculate_percent( 100, 4 ); |
| @@ -97,13 +103,9 @@ | ||
| 97 | 103 | * |
| 98 | 104 | * @param array $ignored_issues The array of ignored issues to add. |
| 99 | 105 | */ |
| 100 | 106 | private function add_ignored_issues( array $ignored_issues ) { |
| 101 | - if ( ! empty( $ignored_issues ) ) { | |
| 102 | - foreach ( $ignored_issues as $issue ) { | |
| 103 | - $this->scan->add_item( $issue->type, $issue->raw_data, Scan_Item::STATUS_IGNORE ); | |
| 104 | - } | |
| 105 | - } | |
| 107 | + $this->scan->carry_forward_ignored_issues( Scan::get_abandoned_types(), $ignored_issues, 'slug' ); | |
| 106 | 108 | } |
| 107 | 109 | |
| 108 | 110 | /** |
| 109 | 111 | * Handle the error by different actions, e.g. logging. |
| @@ -192,13 +194,15 @@ | ||
| 192 | 194 | return $data; |
| 193 | 195 | } |
| 194 | 196 | |
| 195 | 197 | /** |
| 196 | - * Get list of plugin slugs whose names do not match the specified names. | |
| 198 | + * Get list of plugin slugs whose names do not match the specified names on wp.org. | |
| 197 | 199 | */ |
| 198 | 200 | private function get_plugin_slugs_with_mismatched_names(): array { |
| 199 | 201 | return array( |
| 200 | 202 | 'miniorange-malware-protection', |
| 203 | + 'admin-bar-user-switching', | |
| 204 | + 'custom-post-template', | |
| 201 | 205 | ); |
| 202 | 206 | } |
| 203 | 207 | |
| 204 | 208 | /** |
| @@ -208,12 +212,17 @@ | ||
| 208 | 212 | * |
| 209 | 213 | * @return bool |
| 210 | 214 | */ |
| 211 | 215 | public function check_abandoned_plugin_by( string $slug ): bool { |
| 212 | - $premium_plugin_slugs = get_site_option( Plugin_Integrity::PLUGIN_PREMIUM_SLUGS, false ); | |
| 213 | - if ( is_array( $premium_plugin_slugs ) && in_array( $slug, $premium_plugin_slugs, true ) ) { | |
| 216 | + // Check if the plugin is not from wp.org. | |
| 217 | + $premium_plugin_slugs = get_site_option( Plugin_Integrity::PLUGIN_PREMIUM_SLUGS, array() ); | |
| 218 | + if ( ( is_array( $premium_plugin_slugs ) && in_array( $slug, $premium_plugin_slugs, true ) ) | |
| 219 | + || ! $this->is_likely_wporg_slug( $slug ) | |
| 220 | + ) { | |
| 214 | 221 | return true; |
| 215 | - } elseif ( ! $this->is_likely_wporg_slug( $slug ) ) { | |
| 222 | + } | |
| 223 | + if ( $this->scan->is_issue_ignored( $slug ) ) { | |
| 224 | + $this->log( sprintf( 'skip %s because it is already ignored.', $slug ), Scan_Controller::SCAN_LOG ); | |
| 216 | 225 | return true; |
| 217 | 226 | } |
| 218 | 227 | |
| 219 | 228 | $results = $this->handle_wp_org_response_by( $slug ); |
| @@ -228,9 +237,9 @@ | ||
| 228 | 237 | isset( $body_json['name'], $plugin_details['Name'] ) |
| 229 | 238 | && $plugin_details['Name'] !== $body_json['name'] |
| 230 | 239 | && ! in_array( $slug, $this->get_plugin_slugs_with_mismatched_names(), true ) |
| 231 | 240 | ) { |
| 232 | - // This is premium plugin with the same slug as on wp.org but with another name value. | |
| 241 | + // This is a premium plugin with the same slug as on wp.org but with another name OR the plugin developer named the plugin differently on wp.org and inside the main file. | |
| 233 | 242 | return false; |
| 234 | 243 | } |
| 235 | 244 | |
| 236 | 245 | if ( isset( $body_json['error'] ) && 'closed' === $body_json['error'] ) { |