| 1 |
<?php |
| 2 |
namespace Hostinger\Admin\Options; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class for handling plugin options |
| 10 |
*/ |
| 11 |
class PluginOptions { |
| 12 |
/** |
| 13 |
* @var bool |
| 14 |
*/ |
| 15 |
private bool $maintenance_mode = false; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
private string $bypass_code = ''; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var bool |
| 24 |
*/ |
| 25 |
private bool $disable_xml_rpc = false; |
| 26 |
|
| 27 |
/** |
| 28 |
* @var bool |
| 29 |
*/ |
| 30 |
private bool $force_https = false; |
| 31 |
|
| 32 |
/** |
| 33 |
* @var bool |
| 34 |
*/ |
| 35 |
private bool $force_www = false; |
| 36 |
|
| 37 |
/** |
| 38 |
* @var bool |
| 39 |
*/ |
| 40 |
private bool $disable_authentication_password = false; |
| 41 |
|
| 42 |
/** |
| 43 |
* @var bool |
| 44 |
*/ |
| 45 |
private bool $enable_llms_txt = false; |
| 46 |
|
| 47 |
/** |
| 48 |
* @param array $settings plugin settings array. |
| 49 |
*/ |
| 50 |
public function __construct( array $settings = array() ) { |
| 51 |
$this->maintenance_mode = ! empty( $settings['maintenance_mode'] ); |
| 52 |
$this->bypass_code = ! empty( $settings['bypass_code'] ) ? $settings['bypass_code'] : ''; |
| 53 |
$this->disable_xml_rpc = ! empty( $settings['disable_xml_rpc'] ); |
| 54 |
$this->force_https = ! empty( $settings['force_https'] ); |
| 55 |
$this->force_www = ! empty( $settings['force_www'] ); |
| 56 |
$this->disable_authentication_password = ! empty( $settings['disable_authentication_password'] ); |
| 57 |
$this->enable_llms_txt = ! empty( $settings['enable_llms_txt'] ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* @return bool |
| 62 |
*/ |
| 63 |
public function get_maintenance_mode(): bool { |
| 64 |
return $this->maintenance_mode; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* @param bool $maintenance_mode |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
public function set_maintenance_mode( bool $maintenance_mode ): void { |
| 73 |
$this->maintenance_mode = $maintenance_mode; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* @return string |
| 78 |
*/ |
| 79 |
public function get_bypass_code(): string { |
| 80 |
return $this->bypass_code; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* @param string $bypass_code |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
public function set_bypass_code( string $bypass_code ): void { |
| 89 |
$this->bypass_code = $bypass_code; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* @return bool |
| 94 |
*/ |
| 95 |
public function get_disable_xml_rpc(): bool { |
| 96 |
return $this->disable_xml_rpc; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* @param bool $disable_xml_rpc |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
public function set_disable_xml_rpc( bool $disable_xml_rpc ): void { |
| 105 |
$this->disable_xml_rpc = $disable_xml_rpc; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* @return bool |
| 110 |
*/ |
| 111 |
public function get_force_https(): bool { |
| 112 |
return $this->force_https; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* @param bool $force_https |
| 117 |
* |
| 118 |
* @return void |
| 119 |
*/ |
| 120 |
public function set_force_https( bool $force_https ): void { |
| 121 |
$this->force_https = $force_https; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* @return bool |
| 126 |
*/ |
| 127 |
public function get_force_www(): bool { |
| 128 |
return $this->force_www; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* @param bool $force_www |
| 133 |
* |
| 134 |
* @return void |
| 135 |
*/ |
| 136 |
public function set_force_www( bool $force_www ): void { |
| 137 |
$this->force_www = $force_www; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* @return bool |
| 142 |
*/ |
| 143 |
public function get_disable_authentication_password(): bool { |
| 144 |
return $this->disable_authentication_password; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* @param bool $authentication_password |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public function set_disable_authentication_password( bool $authentication_password ): void { |
| 153 |
$this->disable_authentication_password = $authentication_password; |
| 154 |
} |
| 155 |
|
| 156 |
public function get_enable_llms_txt(): bool { |
| 157 |
return $this->enable_llms_txt; |
| 158 |
} |
| 159 |
|
| 160 |
public function set_enable_llms_txt( bool $enable_llms_txt ): void { |
| 161 |
$this->enable_llms_txt = $enable_llms_txt; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* @return array |
| 166 |
*/ |
| 167 |
public function to_array(): array { |
| 168 |
return array( |
| 169 |
'maintenance_mode' => $this->get_maintenance_mode(), |
| 170 |
'bypass_code' => $this->get_bypass_code(), |
| 171 |
'disable_xml_rpc' => $this->get_disable_xml_rpc(), |
| 172 |
'force_https' => $this->get_force_https(), |
| 173 |
'force_www' => $this->get_force_www(), |
| 174 |
'disable_authentication_password' => $this->get_disable_authentication_password(), |
| 175 |
'enable_llms_txt' => $this->get_enable_llms_txt(), |
| 176 |
); |
| 177 |
} |
| 178 |
} |
| 179 |
|