Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Settings | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_settings | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| is_available | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| is_enabled | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| get_defaults | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| get_default_template | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Settings class. |
| 4 | * |
| 5 | * Flagged to be removed after deprecation. |
| 6 | * |
| 7 | * @deprecated 0.38.3 |
| 8 | * |
| 9 | * @package automattic/jetpack-publicize |
| 10 | */ |
| 11 | |
| 12 | namespace Automattic\Jetpack\Publicize\Social_Image_Generator; |
| 13 | |
| 14 | use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings as Jetpack_Social_Settings; |
| 15 | |
| 16 | /** |
| 17 | * This class is used to get and update SIG-specific global settings. |
| 18 | */ |
| 19 | class Settings { |
| 20 | /** |
| 21 | * Name of the database option. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | const OPTION_NAME = 'jetpack_social_image_generator_settings'; |
| 26 | |
| 27 | /** |
| 28 | * Array with SIG's settings. |
| 29 | * |
| 30 | * @var array $settings |
| 31 | */ |
| 32 | public $settings; |
| 33 | |
| 34 | /** |
| 35 | * Constructor. |
| 36 | */ |
| 37 | public function __construct() { |
| 38 | $this->settings = $this->get_settings(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get all current SIG settings. |
| 43 | * |
| 44 | * @return array |
| 45 | */ |
| 46 | private function get_settings() { |
| 47 | $new_settings = ( new Jetpack_Social_Settings() )->get_settings(); |
| 48 | |
| 49 | return array( |
| 50 | 'enabled' => $new_settings['socialImageGeneratorSettings']['enabled'], |
| 51 | 'default_image_id' => $new_settings['socialImageGeneratorSettings']['default_image_id'], |
| 52 | 'defaults' => array( |
| 53 | 'template' => $new_settings['socialImageGeneratorSettings']['template'], |
| 54 | ), |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Check if SIG is available. |
| 60 | * |
| 61 | * @return bool True if SIG is available, false otherwise. |
| 62 | */ |
| 63 | public function is_available() { |
| 64 | return ( new Jetpack_Social_Settings() )->is_sig_available(); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Check if SIG is enabled. |
| 69 | * |
| 70 | * @return bool True if SIG is enabled, false otherwise. |
| 71 | */ |
| 72 | public function is_enabled() { |
| 73 | $new_settings = ( new Jetpack_Social_Settings() )->get_settings(); |
| 74 | |
| 75 | return $new_settings['socialImageGeneratorSettings']['enabled']; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get an array of all current defaults. |
| 80 | * |
| 81 | * @return array |
| 82 | */ |
| 83 | public function get_defaults() { |
| 84 | if ( isset( $this->settings['defaults'] ) ) { |
| 85 | return $this->settings['defaults']; |
| 86 | } |
| 87 | |
| 88 | return array( |
| 89 | 'template' => Templates::DEFAULT_TEMPLATE, |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the current default template. |
| 95 | * |
| 96 | * @return string |
| 97 | */ |
| 98 | public function get_default_template() { |
| 99 | $defaults = $this->get_defaults(); |
| 100 | |
| 101 | return isset( $defaults['template'] ) ? $defaults['template'] : Templates::DEFAULT_TEMPLATE; |
| 102 | } |
| 103 | } |