| 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 |
* @param array $settings plugin settings array. |
| 39 |
*/ |
| 40 |
public function __construct( array $settings = array() ) { |
| 41 |
$this->maintenance_mode = ! empty( $settings['maintenance_mode'] ); |
| 42 |
$this->bypass_code = ! empty( $settings['bypass_code'] ) ? $settings['bypass_code'] : ''; |
| 43 |
$this->disable_xml_rpc = ! empty( $settings['disable_xml_rpc'] ); |
| 44 |
$this->force_https = ! empty( $settings['force_https'] ); |
| 45 |
$this->force_www = ! empty( $settings['force_www'] ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @return bool |
| 50 |
*/ |
| 51 |
public function get_maintenance_mode(): bool { |
| 52 |
return $this->maintenance_mode; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @param bool $maintenance_mode |
| 57 |
* |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public function set_maintenance_mode( bool $maintenance_mode ): void { |
| 61 |
$this->maintenance_mode = $maintenance_mode; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
public function get_bypass_code(): string { |
| 68 |
return $this->bypass_code; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @param string $bypass_code |
| 73 |
* |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
public function set_bypass_code( string $bypass_code ): void { |
| 77 |
$this->bypass_code = $bypass_code; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @return bool |
| 82 |
*/ |
| 83 |
public function get_disable_xml_rpc(): bool { |
| 84 |
return $this->disable_xml_rpc; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* @param bool $disable_xml_rpc |
| 89 |
* |
| 90 |
* @return void |
| 91 |
*/ |
| 92 |
public function set_disable_xml_rpc( bool $disable_xml_rpc ): void { |
| 93 |
$this->disable_xml_rpc = $disable_xml_rpc; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* @return bool |
| 98 |
*/ |
| 99 |
public function get_force_https(): bool { |
| 100 |
return $this->force_https; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* @param bool $force_https |
| 105 |
* |
| 106 |
* @return void |
| 107 |
*/ |
| 108 |
public function set_force_https( bool $force_https ): void { |
| 109 |
$this->force_https = $force_https; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* @return bool |
| 114 |
*/ |
| 115 |
public function get_force_www(): bool { |
| 116 |
return $this->force_www; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* @param bool $force_www |
| 121 |
* |
| 122 |
* @return void |
| 123 |
*/ |
| 124 |
public function set_force_www( bool $force_www ): void { |
| 125 |
$this->force_www = $force_www; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* @return array |
| 130 |
*/ |
| 131 |
public function to_array(): array { |
| 132 |
return array( |
| 133 |
'maintenance_mode' => $this->get_maintenance_mode(), |
| 134 |
'bypass_code' => $this->get_bypass_code(), |
| 135 |
'disable_xml_rpc' => $this->get_disable_xml_rpc(), |
| 136 |
'force_https' => $this->get_force_https(), |
| 137 |
'force_www' => $this->get_force_www(), |
| 138 |
); |
| 139 |
} |
| 140 |
} |
| 141 |
|