-
Notifications
You must be signed in to change notification settings - Fork 1
/
ControllerWP.php
79 lines (62 loc) · 1.59 KB
/
ControllerWP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class ControllerWP
{
public $options;
private static $instance = null;
/**
* @return ControllerWP
*/
public static function getInstance()
{
if (static::$instance === null) {
static::$instance = new self();
}
return static::$instance;
}
public function __clone(){}
public function __wakeup(){}
private function __construct()
{
$this->options = self::get_settings();
}
/**
* Get plugin settings from DB
*
* @return array
*/
public static function get_settings()
{
return get_option( RW_LANG, '' ) ?: [];
}
/**
* Fire! Run tweak options
*/
public function options_loader(){
if(!is_array($this->options)) {
return;
}
foreach ($this->options as $key => $value) {
if($value == '1'){
$this->add_action($key, $value);
} elseif ( is_array($value) ){ // block options
foreach ($value as $name => $val) {
if($val == '1') { // включаем все что не выключено
$this->add_action($name, $val);
}
}
}
}
}
/**
* Запускаем если есть такая функция
*
* @param $function
* @param $settings
*/
protected function add_action( $function, $settings ) {
$function = str_replace('-', '_', $function);
if(function_exists( $function)){
add_action('plugins_loaded', $function, 10);
}
}
}