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 { ...@@ -327,7 +327,8 @@ class Admin {
*/ */
public function register_settings() { public function register_settings() {
Settings::register_settings(); $settings = new Settings();
$settings->register_settings();
} }
} }
...@@ -10,16 +10,16 @@ class Settings { ...@@ -10,16 +10,16 @@ class Settings {
* Settings configuration * Settings configuration
* @var array * @var array
*/ */
private static $settings; private $settings;
/** /**
* Settings init. * Settings class constructor.
* *
* @since 2.0.0 * @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' => [ 'mollie_connected' => [
'type' => 'boolean', 'type' => 'boolean',
'show_in_rest' => true, 'show_in_rest' => true,
...@@ -154,8 +154,7 @@ class Settings { ...@@ -154,8 +154,7 @@ class Settings {
} }
/** /**
* Gets the setting from the database, if no setting available * Gets the setting from the database
* then returns default value.
* *
* @param $name * @param $name
* @return false|mixed|void * @return false|mixed|void
...@@ -173,16 +172,15 @@ class Settings { ...@@ -173,16 +172,15 @@ class Settings {
* *
* @since 2.0.0 * @since 2.0.0
*/ */
public static function register_settings() { public function register_settings() {
self::init(); foreach ($this->settings as $name=>$setting) {
foreach (self::$settings as $name=>$setting) {
register_setting( register_setting(
'kudos_donations', 'kudos_donations',
self::PREFIX . $name, $setting self::PREFIX . $name, $setting
); );
} }
} }
/** /**
...@@ -190,11 +188,9 @@ class Settings { ...@@ -190,11 +188,9 @@ class Settings {
* *
* @since 2.0.0 * @since 2.0.0
*/ */
public static function add_defaults() { public function add_defaults() {
self::init(); foreach ($this->settings as $name=>$setting) {
foreach (self::$settings as $name=>$setting) {
add_option(self::PREFIX . $name, $setting['default'] ?? ''); add_option(self::PREFIX . $name, $setting['default'] ?? '');
} }
...@@ -205,11 +201,9 @@ class Settings { ...@@ -205,11 +201,9 @@ class Settings {
* *
* @since 2.0.0 * @since 2.0.0
*/ */
public static function remove_settings() { public function remove_settings() {
self::init();
foreach ( self::$settings as $key=>$setting ) { foreach ( $this->settings as $key=>$setting ) {
delete_option($key); delete_option($key);
} }
......
...@@ -147,7 +147,9 @@ class ActivatorService { ...@@ -147,7 +147,9 @@ class ActivatorService {
private static function set_defaults() { private static function set_defaults() {
update_option('_kudos_donations_version', KUDOS_VERSION); update_option('_kudos_donations_version', KUDOS_VERSION);
Settings::add_defaults();
$settings = new Settings();
$settings->add_defaults();
} }
} }
...@@ -30,7 +30,8 @@ class DeactivatorService { ...@@ -30,7 +30,8 @@ class DeactivatorService {
public static function deactivate() { public static function deactivate() {
// Clean-up settings from database // 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