-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Readd class-settings classes for initial state population
- Loading branch information
Showing
2 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
projects/packages/publicize/src/auto-conversion-settings/class-settings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Settings class. | ||
* Flagged to be removed after deprecation. | ||
* Jetpack version: 12.9 | ||
* Jetpack Social version: 3.0.0 | ||
* | ||
* @package automattic/jetpack-publicize | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Publicize\Auto_Conversion; | ||
|
||
use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings as Jetpack_Social_Settings; | ||
|
||
/** | ||
* This class is used to get and update Auto_Conversion_Settings. | ||
*/ | ||
class Settings { | ||
/** | ||
* Name of the database option. | ||
* | ||
* @var string | ||
*/ | ||
const OPTION_NAME = 'jetpack_social_settings'; | ||
|
||
/** | ||
* Array with auto conversion settings. | ||
* | ||
* @var array $settings | ||
*/ | ||
public $settings; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$this->settings = $this->get_settings(); | ||
} | ||
|
||
/** | ||
* Get the current auto conversion settings. | ||
* | ||
* @return array | ||
*/ | ||
private function get_settings() { | ||
$new_settings = ( new Jetpack_Social_Settings() )->get_settings(); | ||
|
||
return array( | ||
'image' => $new_settings['autoConversionSettings']['enabled'], | ||
); | ||
} | ||
|
||
/** | ||
* Check if the auto conversion feature is available. | ||
* | ||
* @param string $type Whether video or image. | ||
* @return bool True if available, false otherwise. | ||
*/ | ||
public function is_available( $type ) { | ||
return ( new Jetpack_Social_Settings() )->is_auto_conversion_available( $type ); | ||
} | ||
|
||
/** | ||
* Check if the auto conversion feature is enabled. | ||
* | ||
* @param string $type Whether video or image. | ||
* | ||
* @return bool True if the feature is enabled, false otherwise. | ||
*/ | ||
public function is_enabled( $type ) { | ||
if ( 'image' === $type ) { | ||
$new_settings = ( new Jetpack_Social_Settings() )->get_settings(); | ||
return $new_settings['autoConversionSettings']['enabled']; | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
projects/packages/publicize/src/social-image-generator/class-settings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Settings class. | ||
* | ||
* Flagged to be removed after deprecation. | ||
* Jetpack version: 12.9 | ||
* Jetpack Social version: 3.0.0 | ||
* | ||
* @package automattic/jetpack-publicize | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Publicize\Social_Image_Generator; | ||
|
||
use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings as Jetpack_Social_Settings; | ||
|
||
/** | ||
* This class is used to get and update SIG-specific global settings. | ||
*/ | ||
class Settings { | ||
/** | ||
* Name of the database option. | ||
* | ||
* @var string | ||
*/ | ||
const OPTION_NAME = 'jetpack_social_image_generator_settings'; | ||
|
||
/** | ||
* Array with SIG's settings. | ||
* | ||
* @var array $settings | ||
*/ | ||
public $settings; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$this->settings = $this->get_settings(); | ||
} | ||
|
||
/** | ||
* Get all current SIG settings. | ||
* | ||
* @return array | ||
*/ | ||
private function get_settings() { | ||
$new_settings = ( new Jetpack_Social_Settings() )->get_settings(); | ||
|
||
return array( | ||
'enabled' => $new_settings['socialImageGeneratorSettings']['enabled'], | ||
'defaults' => array( | ||
'template' => $new_settings['socialImageGeneratorSettings']['template'], | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Check if SIG is available. | ||
* | ||
* @return bool True if SIG is available, false otherwise. | ||
*/ | ||
public function is_available() { | ||
return ( new Jetpack_Social_Settings() )->is_sig_available(); | ||
} | ||
|
||
/** | ||
* Check if SIG is enabled. | ||
* | ||
* @return bool True if SIG is enabled, false otherwise. | ||
*/ | ||
public function is_enabled() { | ||
$new_settings = ( new Jetpack_Social_Settings() )->get_settings(); | ||
|
||
return $new_settings['socialImageGeneratorSettings']['enabled']; | ||
} | ||
|
||
/** | ||
* Get an array of all current defaults. | ||
* | ||
* @return array | ||
*/ | ||
public function get_defaults() { | ||
if ( isset( $this->settings['defaults'] ) ) { | ||
return $this->settings['defaults']; | ||
} | ||
|
||
return array( | ||
'template' => Templates::DEFAULT_TEMPLATE, | ||
); | ||
} | ||
|
||
/** | ||
* Get the current default template. | ||
* | ||
* @return string | ||
*/ | ||
public function get_default_template() { | ||
$defaults = $this->get_defaults(); | ||
|
||
return isset( $defaults['template'] ) ? $defaults['template'] : Templates::DEFAULT_TEMPLATE; | ||
} | ||
} |