1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Handles modules loading. |
4
|
|
|
* |
5
|
|
|
* @package Kirki |
6
|
|
|
* @category Core |
7
|
|
|
* @author Aristeides Stathopoulos |
8
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
9
|
|
|
* @license https://opensource.org/licenses/MIT |
10
|
|
|
* @since 3.0.0 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The Kirki_Modules class. |
15
|
|
|
*/ |
16
|
|
|
class Kirki_Modules { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* An array of available modules. |
20
|
|
|
* |
21
|
|
|
* @static |
22
|
|
|
* @access private |
23
|
|
|
* @since 3.0.0 |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $modules = array(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* An array of active modules (objects). |
30
|
|
|
* |
31
|
|
|
* @static |
32
|
|
|
* @access private |
33
|
|
|
* @since 3.0.0 |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private static $active_modules = array(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Constructor. |
40
|
|
|
* |
41
|
|
|
* @access public |
42
|
|
|
* @since 3.0.0 |
43
|
|
|
*/ |
44
|
|
|
public function __construct() { |
45
|
|
|
add_action( 'after_setup_theme', array( $this, 'setup_default_modules' ), 10 ); |
46
|
|
|
add_action( 'after_setup_theme', array( $this, 'init' ), 11 ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set the default modules and apply the 'kirki_modules' filter. |
51
|
|
|
* In v3.0.35 this method was renamed from default_modules to setup_default_modules, |
52
|
|
|
* and its visibility changed from private to public to fix https://github.com/aristath/kirki/issues/2023 |
53
|
|
|
* |
54
|
|
|
* @access public |
55
|
|
|
* @since 3.0.0 |
56
|
|
|
*/ |
57
|
|
|
public function setup_default_modules() { |
58
|
|
|
self::$modules = apply_filters( |
59
|
|
|
'kirki_modules', array( |
|
|
|
|
60
|
|
|
'css' => 'Kirki_Modules_CSS', |
61
|
|
|
'css-vars' => 'Kirki_Modules_CSS_Vars', |
62
|
|
|
'customizer-styling' => 'Kirki_Modules_Customizer_Styling', |
63
|
|
|
'icons' => 'Kirki_Modules_Icons', |
64
|
|
|
'loading' => 'Kirki_Modules_Loading', |
65
|
|
|
'tooltips' => 'Kirki_Modules_Tooltips', |
66
|
|
|
'branding' => 'Kirki_Modules_Customizer_Branding', |
67
|
|
|
'postMessage' => 'Kirki_Modules_PostMessage', |
68
|
|
|
'selective-refresh' => 'Kirki_Modules_Selective_Refresh', |
69
|
|
|
'field-dependencies' => 'Kirki_Modules_Field_Dependencies', |
70
|
|
|
'custom-sections' => 'Kirki_Modules_Custom_Sections', |
71
|
|
|
'webfonts' => 'Kirki_Modules_Webfonts', |
72
|
|
|
'webfont-loader' => 'Kirki_Modules_Webfont_Loader', |
73
|
|
|
'preset' => 'Kirki_Modules_Preset', |
74
|
|
|
'gutenberg' => 'Kirki_Modules_Gutenberg', |
75
|
|
|
'telemetry' => 'Kirki_Modules_Telemetry', |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Instantiates the modules. |
82
|
|
|
* In v3.0.35 the visibility for this method was changed |
83
|
|
|
* from private to public to fix https://github.com/aristath/kirki/issues/2023 |
84
|
|
|
* |
85
|
|
|
* @access public |
86
|
|
|
* @since 3.0.0 |
87
|
|
|
*/ |
88
|
|
|
public function init() { |
89
|
|
|
foreach ( self::$modules as $key => $module_class ) { |
90
|
|
|
if ( class_exists( $module_class ) ) { |
91
|
|
|
// Use this syntax instead of $module_class::get_instance() |
92
|
|
|
// for PHP 5.2 compatibility. |
93
|
|
|
self::$active_modules[ $key ] = call_user_func( array( $module_class, 'get_instance' ) ); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Add a module. |
100
|
|
|
* |
101
|
|
|
* @static |
102
|
|
|
* @access public |
103
|
|
|
* @param string $module The classname of the module to add. |
104
|
|
|
* @since 3.0.0 |
105
|
|
|
*/ |
106
|
|
|
public static function add_module( $module ) { |
107
|
|
|
if ( ! in_array( $module, self::$modules, true ) ) { |
108
|
|
|
self::$modules[] = $module; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Remove a module. |
114
|
|
|
* |
115
|
|
|
* @static |
116
|
|
|
* @access public |
117
|
|
|
* @param string $module The classname of the module to add. |
118
|
|
|
* @since 3.0.0 |
119
|
|
|
*/ |
120
|
|
|
public static function remove_module( $module ) { |
121
|
|
|
$key = array_search( $module, self::$modules, true ); |
122
|
|
|
if ( false !== $key ) { |
123
|
|
|
unset( self::$modules[ $key ] ); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get the modules array. |
129
|
|
|
* |
130
|
|
|
* @static |
131
|
|
|
* @access public |
132
|
|
|
* @since 3.0.0 |
133
|
|
|
* @return array |
134
|
|
|
*/ |
135
|
|
|
public static function get_modules() { |
136
|
|
|
return self::$modules; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Get the array of active modules (objects). |
141
|
|
|
* |
142
|
|
|
* @static |
143
|
|
|
* @access public |
144
|
|
|
* @since 3.0.0 |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
public static function get_active_modules() { |
148
|
|
|
return self::$active_modules; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this: