Commit 072e2d6d authored by Michael Iseard's avatar Michael Iseard
Browse files

Add constructor to settings class

parent c2df7d73
......@@ -327,7 +327,8 @@ class Admin {
*/
public function register_settings() {
Settings::register_settings();
$settings = new Settings();
$settings->register_settings();
}
}
......@@ -10,16 +10,16 @@ class Settings {
* Settings configuration
* @var array
*/
private static $settings;
private $settings;
/**
* Settings init.
* Settings class constructor.
*
* @since 2.0.0
*/
private static function init() {
public function __construct() {
self::$settings = apply_filters('kudos_register_settings', [
$this->settings = apply_filters('kudos_register_settings', [
'mollie_connected' => [
'type' => 'boolean',
'show_in_rest' => true,
......@@ -154,8 +154,7 @@ class Settings {
}
/**
* Gets the setting from the database, if no setting available
* then returns default value.
* Gets the setting from the database
*
* @param $name
* @return false|mixed|void
......@@ -173,16 +172,15 @@ class Settings {
*
* @since 2.0.0
*/
public static function register_settings() {
public function register_settings() {
self::init();
foreach (self::$settings as $name=>$setting) {
foreach ($this->settings as $name=>$setting) {
register_setting(
'kudos_donations',
self::PREFIX . $name, $setting
);
}
}
/**
......@@ -190,11 +188,9 @@ class Settings {
*
* @since 2.0.0
*/
public static function add_defaults() {
public function add_defaults() {
self::init();
foreach (self::$settings as $name=>$setting) {
foreach ($this->settings as $name=>$setting) {
add_option(self::PREFIX . $name, $setting['default'] ?? '');
}
......@@ -205,11 +201,9 @@ class Settings {
*
* @since 2.0.0
*/
public static function remove_settings() {
self::init();
public function remove_settings() {
foreach ( self::$settings as $key=>$setting ) {
foreach ( $this->settings as $key=>$setting ) {
delete_option($key);
}
......
......@@ -147,7 +147,9 @@ class ActivatorService {
private static function set_defaults() {
update_option('_kudos_donations_version', KUDOS_VERSION);
Settings::add_defaults();
$settings = new Settings();
$settings->add_defaults();
}
}
......@@ -30,7 +30,8 @@ class DeactivatorService {
public static function deactivate() {
// Clean-up settings from database
Settings::remove_settings();
$settings = new Settings();
$settings->remove_settings();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment