1 | <?php |
||
16 | class Kirki_Init { |
||
17 | |||
18 | /** |
||
19 | * Control types. |
||
20 | * |
||
21 | * @access private |
||
22 | * @since 3.0.0 |
||
23 | * @var array |
||
24 | */ |
||
25 | private $control_types = array(); |
||
26 | |||
27 | /** |
||
28 | * The class constructor. |
||
29 | */ |
||
30 | public function __construct() { |
||
31 | |||
32 | $this->set_url(); |
||
33 | add_action( 'after_setup_theme', array( $this, 'set_url' ) ); |
||
34 | add_action( 'wp_loaded', array( $this, 'add_to_customizer' ), 1 ); |
||
35 | add_filter( 'kirki/control_types', array( $this, 'default_control_types' ) ); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Properly set the Kirki URL for assets. |
||
40 | * Determines if Kirki is installed as a plugin, in a child theme, or a parent theme |
||
41 | * and then does some calculations to get the proper URL for its CSS & JS assets. |
||
42 | */ |
||
43 | public function set_url() { |
||
90 | |||
91 | /** |
||
92 | * Add the default Kirki control types. |
||
93 | * |
||
94 | * @access public |
||
95 | * @since 3.0.0 |
||
96 | * @param array $control_types The control types array. |
||
97 | * @return array |
||
98 | */ |
||
99 | public function default_control_types( $control_types = array() ) { |
||
100 | |||
101 | $this->control_types = array( |
||
102 | 'checkbox' => 'WP_Customize_Control', |
||
103 | 'kirki-background' => 'Kirki_Control_Background', |
||
104 | 'kirki-code' => 'Kirki_Control_Code', |
||
105 | 'kirki-color' => 'Kirki_Control_Color', |
||
106 | 'kirki-color-palette' => 'Kirki_Control_Color_Palette', |
||
107 | 'kirki-custom' => 'Kirki_Control_Custom', |
||
108 | 'kirki-date' => 'Kirki_Control_Date', |
||
109 | 'kirki-dashicons' => 'Kirki_Control_Dashicons', |
||
110 | 'kirki-dimension' => 'Kirki_Control_Dimension', |
||
111 | 'kirki-dimensions' => 'Kirki_Control_Dimensions', |
||
112 | 'kirki-editor' => 'Kirki_Control_Editor', |
||
113 | 'kirki-fontawesome' => 'Kirki_Control_FontAwesome', |
||
114 | 'kirki-gradient' => 'Kirki_Control_Gradient', |
||
115 | 'kirki-image' => 'Kirki_Control_Image', |
||
116 | 'kirki-multicolor' => 'Kirki_Control_Multicolor', |
||
117 | 'kirki-multicheck' => 'Kirki_Control_MultiCheck', |
||
118 | 'kirki-number' => 'Kirki_Control_Number', |
||
119 | 'kirki-palette' => 'Kirki_Control_Palette', |
||
120 | 'kirki-preset' => 'Kirki_Control_Preset', |
||
121 | 'kirki-radio' => 'Kirki_Control_Radio', |
||
122 | 'kirki-radio-buttonset' => 'Kirki_Control_Radio_ButtonSet', |
||
123 | 'kirki-radio-image' => 'Kirki_Control_Radio_Image', |
||
124 | 'repeater' => 'Kirki_Control_Repeater', |
||
125 | 'kirki-select' => 'Kirki_Control_Select', |
||
126 | 'kirki-slider' => 'Kirki_Control_Slider', |
||
127 | 'kirki-sortable' => 'Kirki_Control_Sortable', |
||
128 | 'kirki-spacing' => 'Kirki_Control_Dimensions', |
||
129 | 'kirki-switch' => 'Kirki_Control_Switch', |
||
130 | 'kirki-generic' => 'Kirki_Control_Generic', |
||
131 | 'kirki-toggle' => 'Kirki_Control_Toggle', |
||
132 | 'kirki-typography' => 'Kirki_Control_Typography', |
||
133 | 'image' => 'Kirki_Control_Image', |
||
134 | 'cropped_image' => 'WP_Customize_Cropped_Image_Control', |
||
135 | 'upload' => 'WP_Customize_Upload_Control', |
||
136 | ); |
||
137 | return array_merge( $control_types, $this->control_types ); |
||
138 | |||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Helper function that adds the fields, sections and panels to the customizer. |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | public function add_to_customizer() { |
||
147 | $this->fields_from_filters(); |
||
148 | add_action( 'customize_register', array( $this, 'register_control_types' ) ); |
||
149 | add_action( 'customize_register', array( $this, 'add_panels' ), 97 ); |
||
150 | add_action( 'customize_register', array( $this, 'add_sections' ), 98 ); |
||
151 | add_action( 'customize_register', array( $this, 'add_fields' ), 99 ); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Register control types |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | public function register_control_types() { |
||
160 | global $wp_customize; |
||
161 | |||
162 | $section_types = apply_filters( 'kirki/section_types', array() ); |
||
163 | foreach ( $section_types as $section_type ) { |
||
164 | $wp_customize->register_section_type( $section_type ); |
||
165 | } |
||
166 | if ( empty( $this->control_types ) ) { |
||
167 | $this->control_types = $this->default_control_types(); |
||
168 | } |
||
169 | $do_not_register_control_types = apply_filters( 'kirki/control_types/exclude', array( |
||
170 | 'Kirki_Control_Repeater', |
||
171 | ) ); |
||
172 | foreach ( $this->control_types as $control_type ) { |
||
173 | if ( 0 === strpos( $control_type, 'Kirki' ) && ! in_array( $control_type, $do_not_register_control_types, true ) && class_exists( $control_type ) ) { |
||
174 | $wp_customize->register_control_type( $control_type ); |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Register our panels to the WordPress Customizer. |
||
181 | * |
||
182 | * @access public |
||
183 | */ |
||
184 | public function add_panels() { |
||
199 | |||
200 | /** |
||
201 | * Register our sections to the WordPress Customizer. |
||
202 | * |
||
203 | * @var object The WordPress Customizer object |
||
204 | * @return void |
||
205 | */ |
||
206 | public function add_sections() { |
||
225 | |||
226 | /** |
||
227 | * Create the settings and controls from the $fields array and register them. |
||
228 | * |
||
229 | * @var object The WordPress Customizer object |
||
230 | * @return void |
||
231 | */ |
||
232 | public function add_fields() { |
||
251 | |||
252 | /** |
||
253 | * Process fields added using the 'kirki/fields' and 'kirki/controls' filter. |
||
254 | * These filters are no longer used, this is simply for backwards-compatibility. |
||
255 | * |
||
256 | * @access private |
||
257 | * @since 2.0.0 |
||
258 | */ |
||
259 | private function fields_from_filters() { |
||
270 | |||
271 | /** |
||
272 | * Alias for the is_plugin static method in the Kirki_Util class. |
||
273 | * This is here for backwards-compatibility purposes. |
||
274 | * |
||
275 | * @static |
||
276 | * @access public |
||
277 | * @since 3.0.0 |
||
278 | * @return bool |
||
279 | */ |
||
280 | public static function is_plugin() { |
||
287 | |||
288 | /** |
||
289 | * Alias for the get_variables static method in the Kirki_Util class. |
||
290 | * This is here for backwards-compatibility purposes. |
||
291 | * |
||
292 | * @static |
||
293 | * @access public |
||
294 | * @since 2.0.0 |
||
295 | * @return array Formatted as array( 'variable-name' => value ). |
||
296 | */ |
||
297 | public static function get_variables() { |
||
304 | |||
305 | } |
||
306 |