Skip to content

Commit

Permalink
Readd class-settings classes for initial state population
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Dec 11, 2023
1 parent e6f1608 commit f617397
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
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'];
}
}
}
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;
}
}

0 comments on commit f617397

Please sign in to comment.