| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_Defender\Model\Setting; |
| 4 |
|
| 5 |
use Calotes\Model\Setting; |
| 6 |
|
| 7 |
class Password_Protection extends Setting { |
| 8 |
public $table = 'wd_password_protection_settings'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Feature status |
| 12 |
* |
| 13 |
* @defender_property |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
public $enabled = false; |
| 17 |
|
| 18 |
/** |
| 19 |
* @defender_property |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
public $user_roles = array(); |
| 23 |
|
| 24 |
/** |
| 25 |
* @defender_property |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
public $pwned_actions = array(); |
| 29 |
|
| 30 |
/** |
| 31 |
* @return array |
| 32 |
*/ |
| 33 |
public function get_default_values() { |
| 34 |
|
| 35 |
return array( |
| 36 |
'message' => __( 'You are required to change your password because the password you are using exists on database breach records.', 'wpdef' ), |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
protected function before_load() { |
| 41 |
$default_values = $this->get_default_values(); |
| 42 |
// Default we will load all rules. |
| 43 |
if ( function_exists( 'get_editable_roles' ) ) { |
| 44 |
// We only need this inside admin, no need to load the user.php everywhere. |
| 45 |
$this->user_roles = array_keys( get_editable_roles() ); |
| 46 |
} else { |
| 47 |
// Define defaults user roles. |
| 48 |
$this->user_roles = array( 'administrator' ); |
| 49 |
} |
| 50 |
$this->pwned_actions = array( |
| 51 |
'force_change_message' => $default_values['message'], |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Define labels for settings key. |
| 57 |
* |
| 58 |
* @param string|null $key |
| 59 |
* |
| 60 |
* @return string|array|null |
| 61 |
*/ |
| 62 |
public function labels( $key = null ) { |
| 63 |
$labels = array( |
| 64 |
'enabled' => __( 'Pwned Passwords', 'wpdef' ), |
| 65 |
'pwned_actions' => __( 'Force password change', 'wpdef' ), |
| 66 |
'user_roles' => __( 'User Roles', 'wpdef' ), |
| 67 |
); |
| 68 |
|
| 69 |
if ( ! is_null( $key ) ) { |
| 70 |
return $labels[ $key ] ?? null; |
| 71 |
} |
| 72 |
|
| 73 |
return $labels; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Check if the model is activated. |
| 78 |
* |
| 79 |
* @return bool |
| 80 |
*/ |
| 81 |
public function is_active() { |
| 82 |
|
| 83 |
return apply_filters( |
| 84 |
'wd_password_protection_enable', |
| 85 |
$this->enabled && count( $this->user_roles ) > 0 |
| 86 |
); |
| 87 |
} |
| 88 |
} |
| 89 |
|