| 1 |
<?php |
| 2 |
namespace Hostinger\Admin\Options; |
| 3 |
|
| 4 |
/** |
| 5 |
* Avoid possibility to get file accessed directly |
| 6 |
*/ |
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
die; |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Class for handling plugin options |
| 13 |
*/ |
| 14 |
class PluginOptions { |
| 15 |
/** |
| 16 |
* @var bool |
| 17 |
*/ |
| 18 |
private bool $maintenance_mode = false; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private string $bypass_code = ''; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var bool |
| 27 |
*/ |
| 28 |
private bool $disable_xml_rpc = false; |
| 29 |
|
| 30 |
/** |
| 31 |
* @var bool |
| 32 |
*/ |
| 33 |
private bool $force_https = false; |
| 34 |
|
| 35 |
/** |
| 36 |
* @var bool |
| 37 |
*/ |
| 38 |
private bool $force_www = false; |
| 39 |
|
| 40 |
/** |
| 41 |
* @param array $settings plugin settings array. |
| 42 |
*/ |
| 43 |
public function __construct( array $settings = array() ) { |
| 44 |
$this->maintenance_mode = !empty($settings['maintenance_mode'] ); |
| 45 |
$this->bypass_code = !empty($settings['bypass_code'] ) ? $settings['bypass_code'] : ''; |
| 46 |
$this->disable_xml_rpc = !empty($settings['disable_xml_rpc'] ); |
| 47 |
$this->force_https = !empty($settings['force_https'] ); |
| 48 |
$this->force_www = !empty($settings['force_www'] ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* @return bool |
| 53 |
*/ |
| 54 |
public function get_maintenance_mode(): bool |
| 55 |
{ |
| 56 |
return $this->maintenance_mode; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* @param bool $maintenance_mode |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
public function set_maintenance_mode(bool $maintenance_mode): void |
| 65 |
{ |
| 66 |
$this->maintenance_mode = $maintenance_mode; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* @return string |
| 71 |
*/ |
| 72 |
public function get_bypass_code(): string |
| 73 |
{ |
| 74 |
return $this->bypass_code; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* @param string $bypass_code |
| 79 |
* |
| 80 |
* @return void |
| 81 |
*/ |
| 82 |
public function set_bypass_code(string $bypass_code): void |
| 83 |
{ |
| 84 |
$this->bypass_code = $bypass_code; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* @return bool |
| 89 |
*/ |
| 90 |
public function get_disable_xml_rpc(): bool |
| 91 |
{ |
| 92 |
return $this->disable_xml_rpc; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* @param bool $disable_xml_rpc |
| 97 |
* |
| 98 |
* @return void |
| 99 |
*/ |
| 100 |
public function set_disable_xml_rpc(bool $disable_xml_rpc): void |
| 101 |
{ |
| 102 |
$this->disable_xml_rpc = $disable_xml_rpc; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* @return bool |
| 107 |
*/ |
| 108 |
public function get_force_https(): bool |
| 109 |
{ |
| 110 |
return $this->force_https; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* @param bool $force_https |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public function set_force_https(bool $force_https): void |
| 119 |
{ |
| 120 |
$this->force_https = $force_https; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* @return bool |
| 125 |
*/ |
| 126 |
public function get_force_www(): bool |
| 127 |
{ |
| 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 |
{ |
| 138 |
$this->force_www = $force_www; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* @return array |
| 143 |
*/ |
| 144 |
public function to_array(): array { |
| 145 |
return array( |
| 146 |
'maintenance_mode' => $this->get_maintenance_mode(), |
| 147 |
'bypass_code' => $this->get_bypass_code(), |
| 148 |
'disable_xml_rpc' => $this->get_disable_xml_rpc(), |
| 149 |
'force_https' => $this->get_force_https(), |
| 150 |
'force_www' => $this->get_force_www(), |
| 151 |
); |
| 152 |
} |
| 153 |
} |