PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.2
Defender Security – Malware Scanner, Login Security & Firewall v6.2.2
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
defender-security / src / model / setting / class-password-protection.php

class-password-protection.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.2, at src/model/setting/class-password-protection.php

118 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle password protection settings.
4 *
5 * @package WP_Defender\Model\Setting
6 */
7
8 namespace WP_Defender\Model\Setting;
9
10 use Calotes\Model\Setting;
11
12 /**
13 * Model for password protection settings.
14 */
15 class Password_Protection extends Setting {
16
17 /**
18 * Option name.
19 *
20 * @var string
21 */
22 protected $table = 'wd_password_protection_settings';
23
24 /**
25 * Feature status
26 *
27 * @defender_property
28 * @var bool
29 */
30 public $enabled = false;
31
32 /**
33 * List of user roles.
34 *
35 * @defender_property
36 * @var array
37 */
38 public $user_roles = array();
39
40 /**
41 * List of pwned actions.
42 *
43 * @defender_property
44 * @var array
45 */
46 public $pwned_actions = array();
47
48 /**
49 * Get default values.
50 *
51 * @return array
52 */
53 public function get_default_values(): array {
54 return array(
55 'message' => esc_html__(
56 'This password has been exposed in a data breach and can’t be used. Choose a different password.',
57 'defender-security'
58 ),
59 );
60 }
61
62 /**
63 * Initializes the object before loading.
64 *
65 * @return void
66 */
67 protected function before_load(): void {
68 $default_values = $this->get_default_values();
69 // Default we will load all rules.
70 if ( function_exists( 'get_editable_roles' ) ) {
71 // We only need this inside admin, no need to load the user.php everywhere.
72 $this->user_roles = array_keys( get_editable_roles() );
73 } else {
74 // Define defaults user roles.
75 $this->user_roles = array( 'administrator' );
76 }
77 $this->pwned_actions = array(
78 'force_change_message' => $default_values['message'],
79 );
80 }
81
82 /**
83 * Define settings labels.
84 *
85 * @return array
86 */
87 public function labels(): array {
88 return array(
89 'enabled' => self::get_module_name(),
90 'pwned_actions' => esc_html__( 'Force password change', 'defender-security' ),
91 'user_roles' => esc_html__( 'User Roles', 'defender-security' ),
92 );
93 }
94
95 /**
96 * Check if the model is activated.
97 *
98 * @return bool
99 */
100 public function is_active(): bool {
101 $enable = apply_filters(
102 'wd_password_protection_enable',
103 $this->enabled && count( $this->user_roles ) > 0
104 );
105
106 return is_bool( $enable ) ? $enable : (bool) $enable;
107 }
108
109 /**
110 * Returns the module name for Pwned Passwords.
111 *
112 * @return string The module name.
113 */
114 public static function get_module_name(): string {
115 return esc_html__( 'Pwned Passwords', 'defender-security' );
116 }
117 }
118