| 1 |
<?php |
| 2 |
|
| 3 |
namespace Texty; |
| 4 |
|
| 5 |
/** |
| 6 |
* Settings Class |
| 7 |
*/ |
| 8 |
class Settings { |
| 9 |
|
| 10 |
/** |
| 11 |
* Option key to hold the settings in database |
| 12 |
*/ |
| 13 |
const OPTION_KEY = 'texty_settings'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Return all the settings |
| 17 |
* |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
public function all() { |
| 21 |
$default = apply_filters( 'texty_settings_default', [ // phpcs:ignore |
| 22 |
'gateway' => '', |
| 23 |
'twilio' => [ |
| 24 |
'sid' => '', |
| 25 |
'token' => '', |
| 26 |
'from' => '', |
| 27 |
], |
| 28 |
'vonage' => [ |
| 29 |
'key' => '', |
| 30 |
'secret' => '', |
| 31 |
'from' => '', |
| 32 |
], |
| 33 |
] ); // phpcs:ignore |
| 34 |
|
| 35 |
$settings = get_option( self::OPTION_KEY, [] ); |
| 36 |
|
| 37 |
return wp_parse_args( $settings, $default ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Get a settings value by key |
| 42 |
* |
| 43 |
* @param string $key |
| 44 |
* |
| 45 |
* @return mixed |
| 46 |
*/ |
| 47 |
public function get( $key ) { |
| 48 |
$settings = $this->all(); |
| 49 |
|
| 50 |
if ( isset( $settings[ $key ] ) ) { |
| 51 |
return $settings[ $key ]; |
| 52 |
} |
| 53 |
|
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get the active gateway name |
| 59 |
* |
| 60 |
* @return string|false |
| 61 |
*/ |
| 62 |
public function gateway() { |
| 63 |
return $this->get( 'gateway' ); |
| 64 |
} |
| 65 |
} |
| 66 |
|