| @@ -63,13 +63,13 @@ | ||
| 63 | 63 | |
| 64 | 64 | public const KEY = 'defender_last_settings', INDEXER = 'defender_config_indexer'; |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * Indicates whether the current installation is a pro version. | |
| 67 | + * Indicates whether the site has a HUB API key (true for both free and pro with Hub connected). | |
| 68 | 68 | * |
| 69 | 69 | * @var bool |
| 70 | 70 | */ |
| 71 | - private $is_pro; | |
| 71 | + private $has_hub_api_key; | |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Constructor for the Backup_Settings class. |
| 75 | 75 | * It initializes the class and sets whether the current installation is a pro version. |
| @@ -74,9 +74,10 @@ | ||
| 74 | 74 | * Constructor for the Backup_Settings class. |
| 75 | 75 | * It initializes the class and sets whether the current installation is a pro version. |
| 76 | 76 | */ |
| 77 | 77 | public function __construct() { |
| 78 | - $this->is_pro = ( new WPMUDEV() )->is_pro(); | |
| 78 | + $wpmudev = wd_di()->get( WPMUDEV::class ); | |
| 79 | + $this->has_hub_api_key = $wpmudev->is_apikey_available(); | |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | /** |
| 82 | 83 | * Changes the format of subscribers in a notification object to an array format. |
| @@ -92,17 +93,17 @@ | ||
| 92 | 93 | && ! is_array( $notification_object->out_house_recipients ) |
| 93 | 94 | ) { |
| 94 | 95 | return array(); |
| 95 | 96 | } |
| 96 | - if ( empty( $notification_object->in_house_recipients ) && empty( $notification_object->out_house_recipients ) ) { | |
| 97 | + if ( array() === $notification_object->in_house_recipients && array() === $notification_object->out_house_recipients ) { | |
| 97 | 98 | return array(); |
| 98 | 99 | } |
| 99 | 100 | |
| 100 | 101 | $subscribers = array(); |
| 101 | - if ( ! empty( $notification_object->in_house_recipients ) ) { | |
| 102 | + if ( array() !== $notification_object->in_house_recipients ) { | |
| 102 | 103 | $subscribers['in_house_recipients'] = $notification_object->in_house_recipients; |
| 103 | 104 | } |
| 104 | - if ( ! empty( $notification_object->out_house_recipients ) ) { | |
| 105 | + if ( array() !== $notification_object->out_house_recipients ) { | |
| 105 | 106 | $subscribers['out_house_recipients'] = $notification_object->out_house_recipients; |
| 106 | 107 | } |
| 107 | 108 | |
| 108 | 109 | return $subscribers; |
| @@ -119,10 +120,8 @@ | ||
| 119 | 120 | $tweak_class->refresh_tweaks_status(); |
| 120 | 121 | $settings = new Model_Security_Tweaks(); |
| 121 | 122 | $tweak_notification = new Tweak_Reminder(); |
| 122 | 123 | $security_tweaks = array( |
| 123 | - 'notification_repeat' => $tweak_notification->configs['reminder'], | |
| 124 | - 'subscribers' => $this->change_subscriber_format( $tweak_notification ), | |
| 125 | 124 | 'notification' => $tweak_notification->status, |
| 126 | 125 | 'data' => $settings->data, |
| 127 | 126 | 'fixed' => $settings->fixed, |
| 128 | 127 | 'issues' => $settings->issues, |
| @@ -140,8 +139,9 @@ | ||
| 140 | 139 | 'check_plugins' => $settings->check_plugins, |
| 141 | 140 | 'check_known_vuln' => $settings->check_known_vuln, |
| 142 | 141 | 'scan_malware' => $settings->scan_malware, |
| 143 | 142 | 'filesize' => $settings->filesize, |
| 143 | + 'check_abandoned_plugin' => $settings->check_abandoned_plugin, | |
| 144 | 144 | // @since 2.7.0 changes for Scheduled options. |
| 145 | 145 | 'scheduled_scanning' => $settings->scheduled_scanning, |
| 146 | 146 | 'day' => $settings->day, |
| 147 | 147 | 'day_n' => $settings->day_n, |
| @@ -167,9 +167,9 @@ | ||
| 167 | 167 | $settings = new Model_Audit_Logging(); |
| 168 | 168 | $audit_report = new Audit_Report(); |
| 169 | 169 | $audit = array( |
| 170 | 170 | 'enabled' => $settings->is_active(), |
| 171 | - 'report' => $audit_report->status, | |
| 171 | + 'report' => 'disabled', | |
| 172 | 172 | 'subscribers' => $this->change_subscriber_format( $audit_report ), |
| 173 | 173 | 'frequency' => $audit_report->frequency, |
| 174 | 174 | 'day' => $audit_report->day, |
| 175 | 175 | 'day_n' => $audit_report->day_n, |
| @@ -177,14 +177,12 @@ | ||
| 177 | 177 | // @since 2.7.0 We can remove it in the next version. |
| 178 | 178 | 'dry_run' => false, |
| 179 | 179 | 'storage_days' => $settings->storage_days, |
| 180 | 180 | ); |
| 181 | - if ( ! $this->is_pro ) { | |
| 182 | - $audit['enabled'] = false; | |
| 183 | - } | |
| 184 | 181 | } else { |
| 185 | 182 | $audit['enabled'] = false; |
| 186 | 183 | } |
| 184 | + | |
| 187 | 185 | $settings_firewall = new Model_Firewall(); |
| 188 | 186 | $settings_ll = new Model_Login_Lockout(); |
| 189 | 187 | $settings_nl = new Model_Notfound_Lockout(); |
| 190 | 188 | $settings_bl = new Model_Blacklist_Lockout(); |
| @@ -265,10 +263,9 @@ | ||
| 265 | 263 | ); |
| 266 | 264 | if ( isset( $audit ) ) { |
| 267 | 265 | $ret['audit'] = $audit; |
| 268 | 266 | } |
| 269 | - // For Blocklist_Monitor. | |
| 270 | - if ( $this->is_pro ) { | |
| 267 | + if ( $this->has_hub_api_key ) { | |
| 271 | 268 | $blocklist_monitor_class = wd_di()->get( Blocklist_Monitor::class ); |
| 272 | 269 | $status = (string) $blocklist_monitor_class->get_status(); |
| 273 | 270 | $ret['blocklist_monitor']['enabled'] = '1' === $status; |
| 274 | 271 | $ret['blocklist_monitor']['status'] = $status; |
| @@ -273,8 +270,9 @@ | ||
| 273 | 270 | $ret['blocklist_monitor']['enabled'] = '1' === $status; |
| 274 | 271 | $ret['blocklist_monitor']['status'] = $status; |
| 275 | 272 | } else { |
| 276 | 273 | $ret['blocklist_monitor']['enabled'] = false; |
| 274 | + $ret['blocklist_monitor']['status'] = '-1'; | |
| 277 | 275 | } |
| 278 | 276 | // For Pwned passwords. |
| 279 | 277 | $pwned_password_model = wd_di()->get( Model_Password_Protection::class ); |
| 280 | 278 | $ret['pwned_passwords']['enabled'] = $pwned_password_model->is_active(); |
| @@ -285,18 +283,14 @@ | ||
| 285 | 283 | $ret['force_strong_password']['enabled'] = $strong_password_model->is_active(); |
| 286 | 284 | $ret['force_strong_password']['user_roles'] = $strong_password_model->user_roles; |
| 287 | 285 | $ret['force_strong_password']['message'] = $strong_password_model->get_message(); |
| 288 | 286 | // For Session Protection. |
| 289 | - if ( $this->is_pro ) { | |
| 290 | - $session_protection_model = wd_di()->get( Session_Protection_Model::class ); | |
| 291 | - $ret['session_protection']['enabled'] = $session_protection_model->enabled; | |
| 292 | - $ret['session_protection']['user_roles'] = $session_protection_model->user_roles; | |
| 293 | - $ret['session_protection']['lock_properties'] = $session_protection_model->lock_properties; | |
| 294 | - $ret['session_protection']['idle_timeout'] = $session_protection_model->idle_timeout; | |
| 295 | - $ret['session_protection']['login_duration'] = $session_protection_model->login_duration; | |
| 296 | - } else { | |
| 297 | - $ret['session_protection']['enabled'] = false; | |
| 298 | - } | |
| 287 | + $session_protection_model = wd_di()->get( Session_Protection_Model::class ); | |
| 288 | + $ret['session_protection']['enabled'] = $session_protection_model->enabled; | |
| 289 | + $ret['session_protection']['user_roles'] = $session_protection_model->user_roles; | |
| 290 | + $ret['session_protection']['lock_properties'] = $session_protection_model->lock_properties; | |
| 291 | + $ret['session_protection']['idle_timeout'] = $session_protection_model->idle_timeout; | |
| 292 | + $ret['session_protection']['login_duration'] = $session_protection_model->login_duration; | |
| 299 | 293 | // It's better to add Tweaks as the last key to eliminate unexpected behavior with possible user logout. |
| 300 | 294 | $ret['security_tweaks'] = $security_tweaks; |
| 301 | 295 | |
| 302 | 296 | return $ret; |
| @@ -309,9 +303,9 @@ | ||
| 309 | 303 | */ |
| 310 | 304 | public function get_configs(): array { |
| 311 | 305 | $keys = get_site_option( self::INDEXER, false ); |
| 312 | 306 | $results = array(); |
| 313 | - if ( empty( $keys ) ) { | |
| 307 | + if ( ! is_array( $keys ) || array() === $keys ) { | |
| 314 | 308 | return $results; |
| 315 | 309 | } |
| 316 | 310 | |
| 317 | 311 | foreach ( $keys as $key ) { |
| @@ -350,9 +344,9 @@ | ||
| 350 | 344 | * @return void |
| 351 | 345 | */ |
| 352 | 346 | public function clear_keys(): void { |
| 353 | 347 | $keys = get_site_option( self::INDEXER, array() ); |
| 354 | - if ( empty( $keys ) ) { | |
| 348 | + if ( array() === $keys ) { | |
| 355 | 349 | delete_site_option( self::INDEXER ); |
| 356 | 350 | delete_site_option( self::KEY ); |
| 357 | 351 | } |
| 358 | 352 | } |
| @@ -361,9 +355,9 @@ | ||
| 361 | 355 | * Clears all configurations from the options table. |
| 362 | 356 | */ |
| 363 | 357 | public function clear_configs(): void { |
| 364 | 358 | $keys = get_site_option( self::INDEXER, false ); |
| 365 | - if ( is_array( $keys ) && ! empty( $keys ) ) { | |
| 359 | + if ( is_array( $keys ) && array() !== $keys ) { | |
| 366 | 360 | foreach ( $keys as $key ) { |
| 367 | 361 | delete_site_option( $key ); |
| 368 | 362 | } |
| 369 | 363 | } |
| @@ -384,9 +378,9 @@ | ||
| 384 | 378 | '%wp_defender_config_%' |
| 385 | 379 | ), |
| 386 | 380 | ARRAY_A |
| 387 | 381 | ); |
| 388 | - if ( ! empty( $result ) ) { | |
| 382 | + if ( array() !== $result ) { | |
| 389 | 383 | foreach ( $result as $arr ) { |
| 390 | 384 | delete_site_option( $arr['option_name'] ); |
| 391 | 385 | } |
| 392 | 386 | } |
| @@ -398,12 +392,13 @@ | ||
| 398 | 392 | * @return void |
| 399 | 393 | */ |
| 400 | 394 | public function maybe_create_default_config(): void { |
| 401 | 395 | $keys = get_site_option( self::INDEXER, array() ); |
| 402 | - if ( empty( $keys ) ) { | |
| 396 | + if ( array() === $keys ) { | |
| 403 | 397 | $this->remove_unindexed_configs(); |
| 404 | - $key = 'wp_defender_config_default' . time(); | |
| 405 | - if ( ! get_site_option( $key ) ) { | |
| 398 | + $key = 'wp_defender_config_default' . time(); | |
| 399 | + $config = get_site_option( $key ); | |
| 400 | + if ( ! is_array( $config ) || array() === $config ) { | |
| 406 | 401 | $this->create_basic_config( $key ); |
| 407 | 402 | } |
| 408 | 403 | } |
| 409 | 404 | } |
| @@ -432,16 +427,19 @@ | ||
| 432 | 427 | $default_ip_lockout_values = ( new Model_Blacklist_Lockout() )->get_default_values(); |
| 433 | 428 | $default_ua_lockout_values = ( new Model_Ua_Lockout() )->get_default_values(); |
| 434 | 429 | $default_password_protection_values = ( new Model_Password_Protection() )->get_default_values(); |
| 435 | 430 | $default_2fa_values = ( new Model_Two_Fa() )->get_default_values(); |
| 431 | + $default_scan_settings = wd_di()->get( Model_Scan::class ); | |
| 432 | + | |
| 436 | 433 | // Total data. |
| 437 | - $data = array( | |
| 434 | + $data = array( | |
| 438 | 435 | 'scan' => array( |
| 439 | 436 | 'integrity_check' => true, |
| 440 | 437 | 'check_core' => true, |
| 441 | 438 | 'check_plugins' => true, |
| 442 | - 'check_known_vuln' => true, | |
| 443 | - 'scan_malware' => true, | |
| 439 | + 'check_known_vuln' => $default_scan_settings->check_known_vuln, | |
| 440 | + 'scan_malware' => $default_scan_settings->scan_malware, | |
| 441 | + 'check_abandoned_plugin' => true, | |
| 444 | 442 | 'filesize' => 3, |
| 445 | 443 | 'report' => 'enabled', |
| 446 | 444 | 'always_send' => false, |
| 447 | 445 | 'report_subscribers' => $default_recipients, |
| @@ -460,9 +458,8 @@ | ||
| 460 | 458 | 'email_subject_error' => $default_scan_notification_values['subject_error'], |
| 461 | 459 | 'email_content_issue_found' => $default_scan_notification_values['content_issue_found'], |
| 462 | 460 | 'email_content_issue_not_found' => $default_scan_notification_values['content_issue_not_found'], |
| 463 | 461 | 'email_content_error' => $default_scan_notification_values['content_error'], |
| 464 | - // @since 2.7.0 move Scheduled options from Malware Scanning - Reporting to Malware settings. | |
| 465 | 462 | // Values for frequency, day and time are above. |
| 466 | 463 | 'scheduled_scanning' => true, |
| 467 | 464 | ), |
| 468 | 465 | 'iplockout' => array( |
| @@ -580,54 +577,52 @@ | ||
| 580 | 577 | 'enabled' => false, |
| 581 | 578 | 'user_roles' => $user_roles, |
| 582 | 579 | 'message' => ( new Strong_Password_Model() )->get_message(), |
| 583 | 580 | ), |
| 584 | - ); | |
| 585 | - // Pro properties. | |
| 586 | - if ( $this->is_pro ) { | |
| 587 | - $data['audit'] = array( | |
| 588 | - 'enabled' => true, | |
| 589 | - 'report' => 'enabled', | |
| 590 | - 'subscribers' => $default_recipients, | |
| 591 | - 'frequency' => 'weekly', | |
| 592 | - 'day' => 'sunday', | |
| 593 | - 'day_n' => 1, | |
| 594 | - 'time' => '4:00', | |
| 595 | - // @since 2.7.0 We can remove it in the next version. | |
| 596 | - 'dry_run' => false, | |
| 597 | - 'storage_days' => '6 months', | |
| 598 | - ); | |
| 599 | - $data['blocklist_monitor'] = array( | |
| 600 | - // @since 2.7.0 Enable. | |
| 601 | - 'enabled' => true, | |
| 602 | - 'status' => '1', | |
| 603 | - ); | |
| 604 | - $data['session_protection'] = array( | |
| 581 | + 'session_protection' => array( | |
| 605 | 582 | 'enabled' => false, |
| 606 | 583 | 'idle_timeout' => 1, |
| 607 | 584 | 'login_duration' => ( new Session_Protection_Model() )->get_default_duration(), |
| 608 | 585 | 'user_roles' => $user_roles, |
| 609 | 586 | 'lock_properties' => array(), |
| 587 | + ), | |
| 588 | + ); | |
| 589 | + $data['audit'] = array( | |
| 590 | + 'enabled' => true, | |
| 591 | + 'report' => 'disabled', | |
| 592 | + 'subscribers' => $default_recipients, | |
| 593 | + 'frequency' => 'weekly', | |
| 594 | + 'day' => 'sunday', | |
| 595 | + 'day_n' => 1, | |
| 596 | + 'time' => '4:00', | |
| 597 | + // @since 2.7.0 We can remove it in the next version. | |
| 598 | + 'dry_run' => false, | |
| 599 | + 'storage_days' => '6 months', | |
| 600 | + ); | |
| 601 | + if ( $this->has_hub_api_key ) { | |
| 602 | + $data['blocklist_monitor'] = array( | |
| 603 | + // @since 2.7.0 Enable. | |
| 604 | + 'enabled' => true, | |
| 605 | + 'status' => '1', | |
| 610 | 606 | ); |
| 611 | 607 | } else { |
| 612 | - $data['audit']['enabled'] = false; | |
| 613 | - $data['blocklist_monitor']['enabled'] = false; | |
| 608 | + $data['blocklist_monitor'] = array( | |
| 609 | + 'enabled' => false, | |
| 610 | + 'status' => '-1', | |
| 611 | + ); | |
| 614 | 612 | } |
| 615 | 613 | // It's better to add Tweaks as the last key to eliminate unexpected behavior with possible user logout. |
| 616 | 614 | $data['security_tweaks'] = array( |
| 617 | - 'notification_repeat' => 'weekly', | |
| 618 | - 'subscribers' => $default_recipients, | |
| 619 | - 'notification' => 'enabled', | |
| 620 | - 'automate' => true, | |
| 621 | - 'data' => array(), | |
| 615 | + 'notification' => 'disabled', | |
| 616 | + 'data' => array(), | |
| 622 | 617 | // @since 2.7.0 Specific values for 4 fixed, 0 ignored and 8 actioned tweaks. 12 tweaks in total. |
| 623 | - 'fixed' => array( | |
| 618 | + 'fixed' => array( | |
| 624 | 619 | 'disable-xml-rpc', |
| 625 | 620 | 'login-duration', |
| 626 | 621 | 'disable-trackback', |
| 627 | 622 | 'prevent-enum-users', |
| 628 | 623 | ), |
| 629 | - 'issues' => array( | |
| 624 | + 'issues' => array( | |
| 630 | 625 | 'php-version', |
| 631 | 626 | 'wp-version', |
| 632 | 627 | 'prevent-php-executed', |
| 633 | 628 | 'protect-information', |
| @@ -635,17 +630,18 @@ | ||
| 635 | 630 | 'security-key', |
| 636 | 631 | 'disable-file-editor', |
| 637 | 632 | 'hide-error', |
| 638 | 633 | ), |
| 639 | - 'ignore' => array(), | |
| 634 | + 'ignore' => array(), | |
| 640 | 635 | ); |
| 641 | 636 | |
| 642 | 637 | $configs['configs'] = $data; |
| 643 | - $configs['strings'] = $this->create_default_module_strings( $data, $this->is_pro ); | |
| 638 | + $configs['strings'] = $this->create_default_module_strings( $data ); | |
| 644 | 639 | $configs['name'] = esc_html__( 'Basic Config', 'defender-security' ); |
| 645 | 640 | $configs['description'] = esc_html__( 'Recommended default protection for every site', 'defender-security' ); |
| 646 | 641 | $configs['immortal'] = true; |
| 647 | 642 | $configs['is_removable'] = true; |
| 643 | + $configs['version'] = 2; | |
| 648 | 644 | update_site_option( $key, $configs ); |
| 649 | 645 | $this->index_key( $key ); |
| 650 | 646 | } |
| 651 | 647 | |
| @@ -660,9 +656,9 @@ | ||
| 660 | 656 | if ( is_array( $keys ) ) { |
| 661 | 657 | $keys[ $key ] = $key; |
| 662 | 658 | $keys = array_unique( $keys ); |
| 663 | 659 | update_site_option( self::INDEXER, $keys ); |
| 664 | - } elseif ( empty( $keys ) ) { | |
| 660 | + } elseif ( '' === $keys ) { | |
| 665 | 661 | // The first config. |
| 666 | 662 | update_site_option( self::INDEXER, array( $key => $key ) ); |
| 667 | 663 | } |
| 668 | 664 | } |
| @@ -734,9 +730,9 @@ | ||
| 734 | 730 | $controller->import_data( $module_data ); |
| 735 | 731 | |
| 736 | 732 | $scan_notification = new Malware_Notification(); |
| 737 | 733 | $scan_report = new Malware_Report(); |
| 738 | - if ( ! empty( $module_data ) ) { | |
| 734 | + if ( array() !== $module_data ) { | |
| 739 | 735 | $scan_settings = new Model_Scan(); |
| 740 | 736 | // For Scan notification. |
| 741 | 737 | if ( isset( $module_data['notification'] ) ) { |
| 742 | 738 | if ( $scan_notification->status !== $module_data['notification'] ) { |
| @@ -747,60 +743,59 @@ | ||
| 747 | 743 | } |
| 748 | 744 | if ( isset( $module_data['error_send'] ) ) { |
| 749 | 745 | $scan_notification->configs['error_send'] = $module_data['error_send']; |
| 750 | 746 | } |
| 751 | - if ( ! empty( $module_data['email_subject_issue_found'] ) ) { | |
| 747 | + if ( isset( $module_data['email_subject_issue_found'] ) && '' !== $module_data['email_subject_issue_found'] ) { | |
| 752 | 748 | $scan_notification->configs['template']['found']['subject'] = $module_data['email_subject_issue_found']; |
| 753 | 749 | } |
| 754 | - if ( ! empty( $module_data['email_subject_issue_not_found'] ) ) { | |
| 750 | + if ( isset( $module_data['email_subject_issue_not_found'] ) && '' !== $module_data['email_subject_issue_not_found'] ) { | |
| 755 | 751 | $scan_notification->configs['template']['not_found']['subject'] = $module_data['email_subject_issue_not_found']; |
| 756 | 752 | } |
| 757 | - if ( ! empty( $module_data['email_subject_error'] ) ) { | |
| 753 | + if ( isset( $module_data['email_subject_error'] ) && '' !== $module_data['email_subject_error'] ) { | |
| 758 | 754 | $scan_notification->configs['template']['error']['subject'] = $module_data['email_subject_error']; |
| 759 | 755 | } |
| 760 | - if ( ! empty( $module_data['email_content_issue_found'] ) ) { | |
| 756 | + if ( isset( $module_data['email_content_issue_found'] ) && '' !== $module_data['email_content_issue_found'] ) { | |
| 761 | 757 | $scan_notification->configs['template']['found']['body'] = $module_data['email_content_issue_found']; |
| 762 | 758 | } |
| 763 | - if ( ! empty( $module_data['email_content_issue_not_found'] ) ) { | |
| 759 | + if ( isset( $module_data['email_content_issue_not_found'] ) && '' !== $module_data['email_content_issue_not_found'] ) { | |
| 764 | 760 | $scan_notification->configs['template']['not_found']['body'] = $module_data['email_content_issue_not_found']; |
| 765 | 761 | } |
| 766 | - if ( ! empty( $module_data['email_content_error'] ) ) { | |
| 762 | + if ( isset( $module_data['email_content_error'] ) && '' !== $module_data['email_content_error'] ) { | |
| 767 | 763 | $scan_notification->configs['template']['error']['body'] = $module_data['email_content_error']; |
| 768 | 764 | } |
| 769 | - if ( ! empty( $module_data['notification_subscribers'] ) ) { | |
| 765 | + if ( | |
| 766 | + isset( $module_data['notification_subscribers'] ) | |
| 767 | + && is_array( $module_data['notification_subscribers'] ) | |
| 768 | + && array() !== $module_data['notification_subscribers'] | |
| 769 | + ) { | |
| 770 | 770 | // Reset all recipients before. |
| 771 | 771 | $scan_notification->in_house_recipients = array(); |
| 772 | 772 | $scan_notification->out_house_recipients = array(); |
| 773 | 773 | foreach ( $module_data['notification_subscribers'] as $key => $subscribers ) { |
| 774 | - $scan_notification->$key = $subscribers; | |
| 774 | + if ( 'in_house_recipients' === $key ) { | |
| 775 | + $scan_notification->in_house_recipients = $subscribers; | |
| 776 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 777 | + $scan_notification->out_house_recipients = $subscribers; | |
| 778 | + } | |
| 775 | 779 | } |
| 776 | 780 | } |
| 777 | 781 | $scan_notification->save(); |
| 778 | 782 | } |
| 779 | - // For Scan report. | |
| 780 | - if ( | |
| 781 | - $this->is_pro | |
| 782 | - && isset( $module_data['report'] ) | |
| 783 | - && $scan_report->status !== $module_data['report'] | |
| 784 | - ) { | |
| 785 | - $scan_report->status = $module_data['report']; | |
| 786 | - } | |
| 787 | 783 | if ( isset( $module_data['always_send'] ) ) { |
| 788 | 784 | $scan_report->configs['always_send'] = $module_data['always_send']; |
| 789 | 785 | } |
| 790 | - if ( ! empty( $module_data['report_subscribers'] ) ) { | |
| 786 | + if ( isset( $module_data['report_subscribers'] ) && is_array( $module_data['report_subscribers'] ) && array() !== $module_data['report_subscribers'] ) { | |
| 791 | 787 | // Reset all recipients before. |
| 792 | 788 | $scan_report->in_house_recipients = array(); |
| 793 | 789 | $scan_report->out_house_recipients = array(); |
| 794 | 790 | foreach ( $module_data['report_subscribers'] as $key => $subscribers ) { |
| 795 | - $scan_report->$key = $subscribers; | |
| 791 | + if ( 'in_house_recipients' === $key ) { | |
| 792 | + $scan_report->in_house_recipients = $subscribers; | |
| 793 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 794 | + $scan_report->out_house_recipients = $subscribers; | |
| 795 | + } | |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | - // @since 2.7.0 Remove 'dry_run'-restoring. | |
| 799 | - // @since 2.7.0 scheduled values. Step#1 if 'report'-key exists. | |
| 800 | - if ( $this->is_pro && isset( $module_data['report'] ) ) { | |
| 801 | - $scan_settings->scheduled_scanning = 'enabled' === $module_data['report']; | |
| 802 | - } | |
| 803 | 798 | // Step#2 if 'scheduled_scanning'-key exists. |
| 804 | 799 | if ( isset( $module_data['scheduled_scanning'] ) ) { |
| 805 | 800 | $scan_settings->scheduled_scanning = $module_data['scheduled_scanning']; |
| 806 | 801 | } |
| @@ -840,9 +835,9 @@ | ||
| 840 | 835 | foreach ( $controller as $lockout_controller ) { |
| 841 | 836 | $lockout_controller->import_data( $module_data ); |
| 842 | 837 | } |
| 843 | 838 | // For Notification and Report. |
| 844 | - if ( ! empty( $module_data ) ) { | |
| 839 | + if ( is_array( $module_data ) && array() !== $module_data ) { | |
| 845 | 840 | // Get string values for notification & report. |
| 846 | 841 | if ( isset( $module_data['notification'] ) ) { |
| 847 | 842 | $lockout_notification = new Firewall_Notification(); |
| 848 | 843 | if ( $lockout_notification->status !== $module_data['notification'] ) { |
| @@ -862,50 +857,23 @@ | ||
| 862 | 857 | } |
| 863 | 858 | if ( isset( $module_data['cooldown_period'] ) ) { |
| 864 | 859 | $lockout_notification->configs['cool_off'] = $module_data['cooldown_period']; |
| 865 | 860 | } |
| 866 | - if ( ! empty( $module_data['notification_subscribers'] ) ) { | |
| 861 | + if ( isset( $module_data['notification_subscribers'] ) && is_array( $module_data['notification_subscribers'] ) && array() !== $module_data['notification_subscribers'] ) { | |
| 867 | 862 | // Reset all recipients before. |
| 868 | 863 | $lockout_notification->in_house_recipients = array(); |
| 869 | 864 | $lockout_notification->out_house_recipients = array(); |
| 870 | 865 | foreach ( $module_data['notification_subscribers'] as $key => $subscribers ) { |
| 871 | - $lockout_notification->$key = $subscribers; | |
| 866 | + if ( 'in_house_recipients' === $key ) { | |
| 867 | + $lockout_notification->in_house_recipients = $subscribers; | |
| 868 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 869 | + $lockout_notification->out_house_recipients = $subscribers; | |
| 870 | + } | |
| 872 | 871 | } |
| 873 | 872 | } |
| 874 | 873 | |
| 875 | 874 | $lockout_notification->save(); |
| 876 | 875 | } |
| 877 | - if ( $this->is_pro && isset( $module_data['report'] ) ) { | |
| 878 | - $lockout_report = new Firewall_Report(); | |
| 879 | - if ( $lockout_report->status !== $module_data['report'] ) { | |
| 880 | - $lockout_report->status = $module_data['report']; | |
| 881 | - } | |
| 882 | - if ( isset( $module_data['day'] ) ) { | |
| 883 | - $lockout_report->day = $module_data['day']; | |
| 884 | - } | |
| 885 | - if ( isset( $module_data['report_frequency'] ) ) { | |
| 886 | - $lockout_report->frequency = $module_data['report_frequency']; | |
| 887 | - } | |
| 888 | - if ( isset( $module_data['day_n'] ) ) { | |
| 889 | - $lockout_report->day_n = (int) $module_data['day_n']; | |
| 890 | - } | |
| 891 | - if ( isset( $module_data['report_time'] ) ) { | |
| 892 | - $lockout_report->time = $module_data['report_time']; | |
| 893 | - } | |
| 894 | - if ( ! empty( $module_data['report_subscribers'] ) ) { | |
| 895 | - // Reset all recipients before. | |
| 896 | - $lockout_report->in_house_recipients = array(); | |
| 897 | - $lockout_report->out_house_recipients = array(); | |
| 898 | - foreach ( $module_data['report_subscribers'] as $key => $subscribers ) { | |
| 899 | - $lockout_report->$key = $subscribers; | |
| 900 | - } | |
| 901 | - } | |
| 902 | - if ( isset( $module_data['last_sent'] ) ) { | |
| 903 | - $lockout_report->last_sent = $module_data['last_sent']; | |
| 904 | - } | |
| 905 | - // @since 2.7.0 Remove 'dry_run'-restoring. | |
| 906 | - $lockout_report->save(); | |
| 907 | - } | |
| 908 | 876 | } else { |
| 909 | 877 | // Default data for lockout notification. |
| 910 | 878 | $lockout_notification = new Firewall_Notification(); |
| 911 | 879 | $lockout_notification->status = 'disabled'; |
| @@ -934,16 +902,9 @@ | ||
| 934 | 902 | // Import. |
| 935 | 903 | $controller->import_data( $module_data ); |
| 936 | 904 | // Report. |
| 937 | 905 | $audit_report = new Audit_Report(); |
| 938 | - if ( ! empty( $module_data ) ) { | |
| 939 | - if ( | |
| 940 | - $this->is_pro | |
| 941 | - && isset( $module_data['report'] ) | |
| 942 | - && $audit_report->status !== $module_data['report'] | |
| 943 | - ) { | |
| 944 | - $audit_report->status = $module_data['report']; | |
| 945 | - } | |
| 906 | + if ( is_array( $module_data ) && array() !== $module_data ) { | |
| 946 | 907 | if ( isset( $module_data['frequency'] ) ) { |
| 947 | 908 | $audit_report->frequency = $module_data['frequency']; |
| 948 | 909 | } |
| 949 | 910 | if ( isset( $module_data['day_n'] ) ) { |
| @@ -954,14 +915,18 @@ | ||
| 954 | 915 | } |
| 955 | 916 | if ( isset( $module_data['time'] ) ) { |
| 956 | 917 | $audit_report->time = $module_data['time']; |
| 957 | 918 | } |
| 958 | - if ( ! empty( $module_data['subscribers'] ) ) { | |
| 919 | + if ( isset( $module_data['subscribers'] ) && is_array( $module_data['subscribers'] ) && array() !== $module_data['subscribers'] ) { | |
| 959 | 920 | // Reset all recipients before. |
| 960 | 921 | $audit_report->in_house_recipients = array(); |
| 961 | 922 | $audit_report->out_house_recipients = array(); |
| 962 | 923 | foreach ( $module_data['subscribers'] as $key => $subscribers ) { |
| 963 | - $audit_report->$key = $subscribers; | |
| 924 | + if ( 'in_house_recipients' === $key ) { | |
| 925 | + $audit_report->in_house_recipients = $subscribers; | |
| 926 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 927 | + $audit_report->out_house_recipients = $subscribers; | |
| 928 | + } | |
| 964 | 929 | } |
| 965 | 930 | } |
| 966 | 931 | if ( isset( $module_data['last_sent'] ) ) { |
| 967 | 932 | $audit_report->last_sent = $module_data['last_sent']; |
| @@ -983,13 +948,13 @@ | ||
| 983 | 948 | * If 'blocklist_monitor' module is activated, 'enabled' set as true. |
| 984 | 949 | */ |
| 985 | 950 | } elseif ( |
| 986 | 951 | 'blocklist_monitor' === $module |
| 987 | - && $this->is_pro | |
| 988 | - && isset( $module_data['status'] ) | |
| 952 | + && $this->has_hub_api_key | |
| 989 | 953 | ) { |
| 990 | 954 | // No need to import data. Just change status. |
| 991 | - ( new Blocklist_Monitor() )->change_status( $module_data['status'] ); | |
| 955 | + $blocklist_status = $module_data['status'] ?? '-1'; | |
| 956 | + ( new Blocklist_Monitor() )->change_status( $blocklist_status ); | |
| 992 | 957 | } elseif ( |
| 993 | 958 | 'pwned_passwords' === $module |
| 994 | 959 | && isset( $module_data['custom_message'] ) |
| 995 | 960 | ) { |
| @@ -995,9 +960,9 @@ | ||
| 995 | 960 | ) { |
| 996 | 961 | $controller->import_data( $module_data ); |
| 997 | 962 | } elseif ( 'force_strong_password' === $module ) { |
| 998 | 963 | $controller->import_data( $module_data ); |
| 999 | - } elseif ( 'session_protection' === $module && $this->is_pro ) { | |
| 964 | + } elseif ( 'session_protection' === $module ) { | |
| 1000 | 965 | $controller->import_data( $module_data ); |
| 1001 | 966 | } elseif ( 'two_factor' === $module ) { |
| 1002 | 967 | $controller->import_data( $module_data ); |
| 1003 | 968 | } elseif ( 'mask_login' === $module ) { |
| @@ -1017,50 +982,13 @@ | ||
| 1017 | 982 | $tweak_class = wd_di()->get( Controller_Security_Tweaks::class ); |
| 1018 | 983 | $need_reauth = $tweak_class->automate( $module_data, $request_reason ); |
| 1019 | 984 | } |
| 1020 | 985 | // For Tweak notification. |
| 1021 | - if ( ! empty( $module_data ) && isset( $module_data['notification'] ) ) { | |
| 986 | + if ( is_array( $module_data ) && array() !== $module_data && isset( $module_data['notification'] ) ) { | |
| 1022 | 987 | $tweak_notification = new Tweak_Reminder(); |
| 1023 | 988 | if ( $tweak_notification->status !== $module_data['notification'] ) { |
| 1024 | - $tweak_notification->status = $module_data['notification']; | |
| 989 | + $tweak_notification->status = 'disabled'; | |
| 1025 | 990 | } |
| 1026 | - | |
| 1027 | - if ( isset( $module_data['notification_repeat'] ) ) { | |
| 1028 | - // Temporary check for older versions. | |
| 1029 | - if ( is_bool( $module_data['notification_repeat'] ) ) { | |
| 1030 | - $tweak_notification->configs['reminder'] = $module_data['notification_repeat'] | |
| 1031 | - ? 'daily' | |
| 1032 | - : 'weekly'; | |
| 1033 | - } elseif ( | |
| 1034 | - is_string( $module_data['notification_repeat'] ) | |
| 1035 | - && in_array( | |
| 1036 | - $module_data['notification_repeat'], | |
| 1037 | - array( | |
| 1038 | - 'daily', | |
| 1039 | - 'weekly', | |
| 1040 | - 'monthly', | |
| 1041 | - ), | |
| 1042 | - true | |
| 1043 | - ) | |
| 1044 | - ) { | |
| 1045 | - $tweak_notification->configs['reminder'] = $module_data['notification_repeat']; | |
| 1046 | - } else { | |
| 1047 | - $tweak_notification->configs['reminder'] = 'weekly'; | |
| 1048 | - } | |
| 1049 | - } else { | |
| 1050 | - $tweak_notification->configs['reminder'] = 'weekly'; | |
| 1051 | - } | |
| 1052 | - if ( ! empty( $module_data['subscribers'] ) ) { | |
| 1053 | - // Reset all recipients before. | |
| 1054 | - $tweak_notification->in_house_recipients = array(); | |
| 1055 | - $tweak_notification->out_house_recipients = array(); | |
| 1056 | - foreach ( $module_data['subscribers'] as $key => $subscribers ) { | |
| 1057 | - $tweak_notification->$key = $subscribers; | |
| 1058 | - } | |
| 1059 | - } | |
| 1060 | - if ( isset( $module_data['last_sent'] ) ) { | |
| 1061 | - $tweak_notification->last_sent = $module_data['last_sent']; | |
| 1062 | - } | |
| 1063 | 991 | $tweak_notification->save(); |
| 1064 | 992 | } |
| 1065 | 993 | } |
| 1066 | 994 | } |
| @@ -1078,9 +1006,9 @@ | ||
| 1078 | 1006 | * |
| 1079 | 1007 | * @return array Returns an array containing parsed data for import. |
| 1080 | 1008 | */ |
| 1081 | 1009 | public function parse_data_for_import( $configs = null ): array { |
| 1082 | - if ( empty( $configs ) ) { | |
| 1010 | + if ( ! is_array( $configs ) || array() === $configs ) { | |
| 1083 | 1011 | $configs = $this->gather_data(); |
| 1084 | 1012 | } |
| 1085 | 1013 | $strings = array(); |
| 1086 | 1014 | foreach ( $configs as $module => $module_data ) { |
| @@ -1162,9 +1090,10 @@ | ||
| 1162 | 1090 | * |
| 1163 | 1091 | * @return bool Returns true if the new structure is used, otherwise false. |
| 1164 | 1092 | */ |
| 1165 | 1093 | public function check_for_new_structure( array $configs ): bool { |
| 1166 | - return array_key_exists( 'subscribers', $configs['security_tweaks'] ); | |
| 1094 | + return isset( $configs['version'] ) || | |
| 1095 | + ( isset( $configs['security_tweaks'] ) && array_key_exists( 'enabled_user_enums', $configs['security_tweaks'] ) ); | |
| 1167 | 1096 | } |
| 1168 | 1097 | |
| 1169 | 1098 | /** |
| 1170 | 1099 | * Verifies the integrity of configuration data. |
| @@ -1173,10 +1102,11 @@ | ||
| 1173 | 1102 | * |
| 1174 | 1103 | * @return bool Returns true if the data is valid, otherwise false. |
| 1175 | 1104 | */ |
| 1176 | 1105 | public function verify_config_data( $data ): bool { |
| 1177 | - if ( ! isset( $data['name'], $data['configs'], $data['strings'] ) | |
| 1178 | - || empty( $data['name'] ) || empty( $data['strings'] ) | |
| 1106 | + if ( | |
| 1107 | + ! isset( $data['name'], $data['configs'], $data['strings'] ) | |
| 1108 | + || '' === $data['name'] || ! is_array( $data['strings'] ) || array() === $data['strings'] | |
| 1179 | 1109 | ) { |
| 1180 | 1110 | return false; |
| 1181 | 1111 | } |
| 1182 | 1112 | |
| @@ -1190,50 +1120,41 @@ | ||
| 1190 | 1120 | * |
| 1191 | 1121 | * @return array Returns an array of imported module strings. |
| 1192 | 1122 | */ |
| 1193 | 1123 | public function import_module_strings( array $data ): array { |
| 1194 | - if ( empty( $data['strings'] ) ) { | |
| 1124 | + if ( ! isset( $data['strings'] ) || ! is_array( $data['strings'] ) || array() === $data['strings'] ) { | |
| 1195 | 1125 | return array(); |
| 1196 | 1126 | } |
| 1197 | 1127 | |
| 1198 | 1128 | foreach ( $data['configs'] as $key => $config ) { |
| 1199 | - if ( | |
| 1200 | - 'security_tweaks' === $key | |
| 1201 | - && 'enabled' === $config['notification'] | |
| 1202 | - && 1 === ( is_array( $data['strings']['security_tweaks'] ) | |
| 1203 | - || $data['strings']['security_tweaks'] instanceof Countable ? count( $data['strings']['security_tweaks'] ) : 0 ) | |
| 1204 | - ) { | |
| 1205 | - $data['strings']['security_tweaks'][] = esc_html__( 'Email notifications active', 'defender-security' ); | |
| 1129 | + if ( 'security_tweaks' === $key ) { | |
| 1130 | + $data['strings']['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( $config ); | |
| 1206 | 1131 | } elseif ( 'scan' === $key ) { |
| 1207 | - $data['strings']['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( | |
| 1208 | - $config, | |
| 1209 | - $this->is_pro | |
| 1210 | - ); | |
| 1132 | + $data['strings']['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config ); | |
| 1211 | 1133 | } elseif ( 'iplockout' === $key ) { |
| 1212 | - $data['strings']['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( | |
| 1213 | - $config, | |
| 1214 | - $this->is_pro | |
| 1215 | - ); | |
| 1134 | + $data['strings']['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config ); | |
| 1216 | 1135 | } elseif ( 'audit' === $key ) { |
| 1217 | 1136 | // Additional check for Free version. |
| 1218 | 1137 | $config = is_array( $config ) ? $config : array(); |
| 1219 | - $data['strings']['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( | |
| 1220 | - $config, | |
| 1221 | - $this->is_pro | |
| 1222 | - ); | |
| 1138 | + $data['strings']['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config ); | |
| 1223 | 1139 | } elseif ( 'blocklist_monitor' === $key ) { |
| 1224 | 1140 | // Additional check for Free version. |
| 1225 | 1141 | $config = is_array( $config ) ? $config : array(); |
| 1226 | - $data['strings']['blocklist_monitor'] = $this->format_blocklist_monitor_strings( | |
| 1227 | - $config, | |
| 1228 | - $this->is_pro | |
| 1229 | - ); | |
| 1142 | + $data['strings']['blocklist_monitor'] = $this->format_blocklist_monitor_strings( $config ); | |
| 1230 | 1143 | } elseif ( 'pwned_passwords' === $key ) { |
| 1231 | - $data['strings']['pwned_passwords'] = wd_di()->get( Controller_Password_Protection::class )->config_strings( | |
| 1232 | - $config, | |
| 1233 | - $this->is_pro | |
| 1234 | - ); | |
| 1144 | + $data['strings']['pwned_passwords'] = wd_di()->get( Controller_Password_Protection::class )->config_strings( $config ); | |
| 1145 | + } elseif ( 'mask_login' === $key ) { | |
| 1146 | + $data['strings']['mask_login'] = wd_di()->get( Controller_Mask_Login::class )->config_strings( $config ); | |
| 1147 | + } elseif ( 'security_headers' === $key ) { | |
| 1148 | + $config = is_array( $config ) ? $config : array(); | |
| 1149 | + $data['strings']['security_headers'] = wd_di()->get( Security_Headers::class )->config_strings( $config ); | |
| 1150 | + } elseif ( 'two_factor' === $key ) { | |
| 1151 | + // Two-Factor is available on both Free and Pro. | |
| 1152 | + $data['strings']['two_factor'] = wd_di()->get( Two_Factor::class )->config_strings( $config ); | |
| 1153 | + } elseif ( 'force_strong_password' === $key ) { | |
| 1154 | + $data['strings']['force_strong_password'] = wd_di()->get( Strong_Password_Controller::class )->config_strings( $config ); | |
| 1235 | 1155 | } |
| 1156 | + // todo: display session_protection strings. | |
| 1236 | 1157 | } |
| 1237 | 1158 | |
| 1238 | 1159 | return $data['strings']; |
| 1239 | 1160 | } |
| @@ -1240,45 +1161,38 @@ | ||
| 1240 | 1161 | |
| 1241 | 1162 | /** |
| 1242 | 1163 | * Creates default module strings for the Basic configuration. |
| 1243 | 1164 | * |
| 1244 | - * @param array $configs The configuration data. | |
| 1245 | - * @param bool $is_pro Whether the current installation is a pro version. | |
| 1165 | + * @param array $configs The configuration data. | |
| 1246 | 1166 | * |
| 1247 | 1167 | * @return array Returns an array of default module strings. |
| 1248 | 1168 | */ |
| 1249 | - public function create_default_module_strings( array $configs, bool $is_pro ): array { | |
| 1169 | + public function create_default_module_strings( array $configs ): array { | |
| 1250 | 1170 | $strings = array(); |
| 1171 | + | |
| 1251 | 1172 | foreach ( $configs as $key => $config ) { |
| 1252 | 1173 | if ( 'security_tweaks' === $key ) { |
| 1253 | - $strings['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( | |
| 1254 | - $config, | |
| 1255 | - $is_pro | |
| 1256 | - ); | |
| 1174 | + $strings['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( $config ); | |
| 1257 | 1175 | } elseif ( 'scan' === $key ) { |
| 1258 | - $strings['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config, $is_pro ); | |
| 1176 | + $strings['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config ); | |
| 1259 | 1177 | } elseif ( 'iplockout' === $key ) { |
| 1260 | - $strings['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config, $is_pro ); | |
| 1178 | + $strings['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config ); | |
| 1261 | 1179 | } elseif ( 'audit' === $key ) { |
| 1262 | - $strings['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config, $is_pro ); | |
| 1180 | + $strings['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config ); | |
| 1263 | 1181 | } elseif ( 'two_factor' === $key ) { |
| 1264 | 1182 | $strings['two_factor'][] = esc_html__( 'Inactive', 'defender-security' ); |
| 1265 | 1183 | } elseif ( 'mask_login' === $key ) { |
| 1266 | - $strings['mask_login'][] = esc_html__( 'Inactive', 'defender-security' ); | |
| 1184 | + $strings['mask_login'] = wd_di()->get( Controller_Mask_Login::class )->config_strings( $config ); | |
| 1267 | 1185 | } elseif ( 'security_headers' === $key ) { |
| 1268 | - $strings['security_headers'][] = esc_html__( 'Active', 'defender-security' ); | |
| 1186 | + $strings['security_headers'] = wd_di()->get( Security_Headers::class )->config_strings( $config ); | |
| 1269 | 1187 | } elseif ( 'blocklist_monitor' === $key ) { |
| 1270 | - $strings['blocklist_monitor'] = wd_di()->get( Blocklist_Monitor::class )->config_strings( | |
| 1271 | - $config, | |
| 1272 | - $is_pro | |
| 1273 | - ); | |
| 1188 | + $strings['blocklist_monitor'] = wd_di()->get( Blocklist_Monitor::class )->config_strings( $config ); | |
| 1274 | 1189 | } elseif ( 'pwned_passwords' === $key ) { |
| 1275 | 1190 | $strings['pwned_passwords'][] = esc_html__( 'Inactive', 'defender-security' ); |
| 1276 | 1191 | } elseif ( 'force_strong_password' === $key ) { |
| 1277 | 1192 | $strings['force_strong_password'][] = esc_html__( 'Inactive', 'defender-security' ); |
| 1278 | - } elseif ( 'session_protection' === $key ) { | |
| 1279 | - $strings['session_protection'][] = esc_html__( 'Inactive', 'defender-security' ); | |
| 1280 | 1193 | } |
| 1194 | + // todo: display session_protection strings. | |
| 1281 | 1195 | } |
| 1282 | 1196 | |
| 1283 | 1197 | return $strings; |
| 1284 | 1198 | } |
| @@ -1291,9 +1205,9 @@ | ||
| 1291 | 1205 | * @return array Returns the decoded settings array. |
| 1292 | 1206 | */ |
| 1293 | 1207 | private function get_decoded_settings( string $key ): array { |
| 1294 | 1208 | $data = get_site_option( $key ); |
| 1295 | - if ( $data && is_string( $data ) ) { | |
| 1209 | + if ( is_string( $data ) && '' !== trim( $data ) ) { | |
| 1296 | 1210 | $decoded_data = json_decode( $data, true ); |
| 1297 | 1211 | if ( is_array( $decoded_data ) ) { |
| 1298 | 1212 | return $decoded_data; |
| 1299 | 1213 | } |
| @@ -1308,9 +1222,9 @@ | ||
| 1308 | 1222 | * @return array |
| 1309 | 1223 | */ |
| 1310 | 1224 | private function get_prev_settings(): array { |
| 1311 | 1225 | $arr = array(); |
| 1312 | - if ( $this->is_pro ) { | |
| 1226 | + if ( $this->has_hub_api_key ) { | |
| 1313 | 1227 | $status = (string) wd_di()->get( Blocklist_Monitor::class )->get_status(); |
| 1314 | 1228 | $arr['enabled'] = '1' === $status; |
| 1315 | 1229 | $arr['status'] = $status; |
| 1316 | 1230 | } else { |
| @@ -1341,11 +1255,11 @@ | ||
| 1341 | 1255 | */ |
| 1342 | 1256 | private function module_to_name( string $module ): string { |
| 1343 | 1257 | switch ( $module ) { |
| 1344 | 1258 | case 'security_tweaks': |
| 1345 | - return esc_html__( 'Security Recommendations', 'defender-security' ); | |
| 1259 | + return esc_html__( 'Hardening', 'defender-security' ); | |
| 1346 | 1260 | case 'scan': |
| 1347 | - return esc_html__( 'Malware Scanning', 'defender-security' ); | |
| 1261 | + return esc_html__( 'Issue', 'defender-security' ); | |
| 1348 | 1262 | case 'audit': |
| 1349 | 1263 | return Model_Audit_Logging::get_module_name(); |
| 1350 | 1264 | case 'iplockout': |
| 1351 | 1265 | return esc_html__( 'Firewall', 'defender-security' ); |
| @@ -1471,39 +1385,21 @@ | ||
| 1471 | 1385 | ); |
| 1472 | 1386 | } |
| 1473 | 1387 | |
| 1474 | 1388 | /** |
| 1475 | - * Format strings of Block list Monitor config. | |
| 1389 | + * Format strings of Blocklist Monitor config. | |
| 1476 | 1390 | * |
| 1477 | 1391 | * @param array $config Saved config. |
| 1478 | - * @param bool $is_pro User membership status. | |
| 1479 | 1392 | * |
| 1480 | 1393 | * @return array |
| 1481 | 1394 | */ |
| 1482 | - private function format_blocklist_monitor_strings( array $config, bool $is_pro ): array { | |
| 1483 | - // If Block list Monitor is enable. | |
| 1484 | - if ( isset( $config['status'] ) && '1' === (string) $config['status'] ) { | |
| 1485 | - if ( $is_pro ) { | |
| 1486 | - $monitor = array( esc_html__( 'Active', 'defender-security' ) ); | |
| 1487 | - } else { | |
| 1488 | - $monitor = array( | |
| 1489 | - sprintf( | |
| 1490 | - /* translators: %s: Html for Pro-tag. */ | |
| 1491 | - esc_html__( 'Active %s', 'defender-security' ), | |
| 1492 | - '<span class="sui-tag sui-tag-pro">Pro</span>' | |
| 1493 | - ), | |
| 1494 | - ); | |
| 1495 | - } | |
| 1496 | - } elseif ( $is_pro ) { | |
| 1497 | - $monitor = array( esc_html__( 'Inactive', 'defender-security' ) ); | |
| 1395 | + private function format_blocklist_monitor_strings( array $config ): array { | |
| 1396 | + if ( $this->has_hub_api_key ) { | |
| 1397 | + $monitor = isset( $config['status'] ) && '1' === (string) $config['status'] | |
| 1398 | + ? array( esc_html__( 'Blocklist Monitor active', 'defender-security' ) ) | |
| 1399 | + : array( esc_html__( 'Blocklist Monitor inactive', 'defender-security' ) ); | |
| 1498 | 1400 | } else { |
| 1499 | - $monitor = array( | |
| 1500 | - sprintf( | |
| 1501 | - /* translators: %s: Html for Pro-tag. */ | |
| 1502 | - esc_html__( 'Inactive %s', 'defender-security' ), | |
| 1503 | - '<span class="sui-tag sui-tag-pro">Pro</span>' | |
| 1504 | - ), | |
| 1505 | - ); | |
| 1401 | + $monitor = array( esc_html__( 'Blocklist Monitor inactive', 'defender-security' ) ); | |
| 1506 | 1402 | } |
| 1507 | 1403 | |
| 1508 | 1404 | return $monitor; |
| 1509 | 1405 | } |