PluginOptions.php
194 lines
| 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 | * @var bool |
| 49 | */ |
| 50 | private bool $optin_mcp = false; |
| 51 | |
| 52 | /** |
| 53 | * @param array $settings plugin settings array. |
| 54 | */ |
| 55 | public function __construct( array $settings = array() ) { |
| 56 | $this->maintenance_mode = ! empty( $settings['maintenance_mode'] ); |
| 57 | $this->bypass_code = ! empty( $settings['bypass_code'] ) ? $settings['bypass_code'] : ''; |
| 58 | $this->disable_xml_rpc = ! empty( $settings['disable_xml_rpc'] ); |
| 59 | $this->force_https = ! empty( $settings['force_https'] ); |
| 60 | $this->force_www = ! empty( $settings['force_www'] ); |
| 61 | $this->disable_authentication_password = ! empty( $settings['disable_authentication_password'] ); |
| 62 | $this->enable_llms_txt = ! empty( $settings['enable_llms_txt'] ); |
| 63 | $this->optin_mcp = ! empty( $settings['optin_mcp'] ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return bool |
| 68 | */ |
| 69 | public function get_maintenance_mode(): bool { |
| 70 | return $this->maintenance_mode; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @param bool $maintenance_mode |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | public function set_maintenance_mode( bool $maintenance_mode ): void { |
| 79 | $this->maintenance_mode = $maintenance_mode; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return string |
| 84 | */ |
| 85 | public function get_bypass_code(): string { |
| 86 | return $this->bypass_code; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param string $bypass_code |
| 91 | * |
| 92 | * @return void |
| 93 | */ |
| 94 | public function set_bypass_code( string $bypass_code ): void { |
| 95 | $this->bypass_code = $bypass_code; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @return bool |
| 100 | */ |
| 101 | public function get_disable_xml_rpc(): bool { |
| 102 | return $this->disable_xml_rpc; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @param bool $disable_xml_rpc |
| 107 | * |
| 108 | * @return void |
| 109 | */ |
| 110 | public function set_disable_xml_rpc( bool $disable_xml_rpc ): void { |
| 111 | $this->disable_xml_rpc = $disable_xml_rpc; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @return bool |
| 116 | */ |
| 117 | public function get_force_https(): bool { |
| 118 | return $this->force_https; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @param bool $force_https |
| 123 | * |
| 124 | * @return void |
| 125 | */ |
| 126 | public function set_force_https( bool $force_https ): void { |
| 127 | $this->force_https = $force_https; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @return bool |
| 132 | */ |
| 133 | public function get_force_www(): bool { |
| 134 | return $this->force_www; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * @param bool $force_www |
| 139 | * |
| 140 | * @return void |
| 141 | */ |
| 142 | public function set_force_www( bool $force_www ): void { |
| 143 | $this->force_www = $force_www; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @return bool |
| 148 | */ |
| 149 | public function get_disable_authentication_password(): bool { |
| 150 | return $this->disable_authentication_password; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @param bool $authentication_password |
| 155 | * |
| 156 | * @return void |
| 157 | */ |
| 158 | public function set_disable_authentication_password( bool $authentication_password ): void { |
| 159 | $this->disable_authentication_password = $authentication_password; |
| 160 | } |
| 161 | |
| 162 | public function get_enable_llms_txt(): bool { |
| 163 | return $this->enable_llms_txt; |
| 164 | } |
| 165 | |
| 166 | public function set_enable_llms_txt( bool $llmstxt_enabled ): void { |
| 167 | $this->enable_llms_txt = $llmstxt_enabled; |
| 168 | } |
| 169 | |
| 170 | public function get_optin_mcp(): bool { |
| 171 | return $this->optin_mcp; |
| 172 | } |
| 173 | |
| 174 | public function set_optin_mcp( bool $optin_mcp ): void { |
| 175 | $this->optin_mcp = $optin_mcp; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @return array |
| 180 | */ |
| 181 | public function to_array(): array { |
| 182 | return array( |
| 183 | 'maintenance_mode' => $this->get_maintenance_mode(), |
| 184 | 'bypass_code' => $this->get_bypass_code(), |
| 185 | 'disable_xml_rpc' => $this->get_disable_xml_rpc(), |
| 186 | 'force_https' => $this->get_force_https(), |
| 187 | 'force_www' => $this->get_force_www(), |
| 188 | 'disable_authentication_password' => $this->get_disable_authentication_password(), |
| 189 | 'enable_llms_txt' => $this->get_enable_llms_txt(), |
| 190 | 'optin_mcp' => $this->get_optin_mcp(), |
| 191 | ); |
| 192 | } |
| 193 | } |
| 194 |