PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / compatibility / src / Kirki.php
kirki / customizer / packages / compatibility / src Last commit date
deprecated 1 month ago Aliases.php 2 months ago Config.php 5 months ago Control.php 5 months ago Deprecated.php 5 months ago Field.php 2 months ago Framework.php 5 months ago Init.php 2 months ago Kirki.php 2 months ago Modules.php 2 months ago Pro_Namespace_Compatibility.php 5 months ago Sanitize_Values.php 5 months ago Scripts.php 2 months ago Settings.php 5 months ago Values.php 5 months ago
Kirki.php
305 lines
1 <?php
2 /**
3 * The Kirki API class.
4 * Takes care of adding panels, sections & fields to the customizer.
5 * For documentation please see https://github.com/aristath/kirki/wiki
6 *
7 * @package Kirki
8 * @category Core
9 * @author Themeum
10 * @copyright Copyright (c) 2023, Themeum
11 * @license https://opensource.org/licenses/MIT
12 * @since 1.0
13 */
14
15 namespace Kirki\Compatibility;
16
17 // ? Bagus: do we really need these? They are already under the same namespace as Kirki class (this file).
18 use Kirki\Compatibility\Config;
19 use Kirki\Compatibility\Field;
20
21 // Exit if accessed directly.
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * This class acts as an interface.
28 * Developers may use this object to add configurations, fields, panels and sections.
29 * You can also access all available configurations, fields, panels and sections
30 * by accessing the object's static properties.
31 */
32 class Kirki extends Init {
33
34 /**
35 * URL to the Kirki folder.
36 *
37 * @deprecated This is no longer used. Only kept here for backwards compatibility to avoid fatal errors.
38 * @static
39 * @access public
40 * @var string
41 */
42 public static $url;
43
44 /**
45 * An array containing all configurations.
46 *
47 * @static
48 * @access public
49 * @var array
50 */
51 public static $config = [];
52
53 /**
54 * An array containing all fields for compatibility purpose.
55 *
56 * @static
57 * @access public
58 * @var array
59 */
60 public static $fields = [];
61
62 /**
63 * An array containing all fields.
64 *
65 * @static
66 * @access public
67 * @var array
68 */
69 public static $all_fields = [];
70
71 /**
72 * An array containing all controls to be removed.
73 *
74 * @static
75 * @access public
76 * @since 3.0.17
77 * @var array
78 */
79 public static $controls_to_remove = [];
80
81 /**
82 * Modules object.
83 *
84 * @access public
85 * @since 3.0.0
86 * @var object
87 */
88 public $modules;
89
90 /**
91 * Get the value of an option from the db.
92 *
93 * @static
94 * @access public
95 * @param string $config_id The ID of the configuration corresponding to this field.
96 * @param string $field_id The field_id (defined as 'settings' in the field arguments).
97 * @return mixed The saved value of the field.
98 */
99 public static function get_option( $config_id = '', $field_id = '' ) {
100
101 return Values::get_value( $config_id, $field_id );
102
103 }
104
105 /**
106 * Sets the configuration options.
107 *
108 * @static
109 * @access public
110 * @param string $config_id The configuration ID.
111 * @param array $args The configuration options.
112 */
113 public static function add_config( $config_id, $args = [] ) {
114
115 $config = Config::get_instance( $config_id, $args );
116 $config_args = $config->get_config();
117
118 self::$config[ $config_args['id'] ] = $config_args;
119
120 }
121
122 /**
123 * Create a new panel.
124 *
125 * @static
126 * @access public
127 * @param string $id The ID for this panel.
128 * @param array $args The panel arguments.
129 */
130 public static function add_panel( $id = '', $args = [] ) {
131
132 new \Kirki\Panel( $id, $args );
133
134 }
135
136 /**
137 * Remove a panel.
138 *
139 * @static
140 * @access public
141 * @since 3.0.17
142 * @param string $id The ID for this panel.
143 */
144 public static function remove_panel( $id = '' ) {
145
146 $panel = new \Kirki\Panel( $id );
147 $panel->remove();
148
149 }
150
151 /**
152 * Create a new section.
153 *
154 * @static
155 * @access public
156 * @param string $id The ID for this section.
157 * @param array $args The section arguments.
158 */
159 public static function add_section( $id, $args ) {
160
161 new \Kirki\Section( $id, $args );
162
163 }
164
165 /**
166 * Remove a section.
167 *
168 * @static
169 * @access public
170 * @since 3.0.17
171 * @param string $id The ID for this section.
172 */
173 public static function remove_section( $id = '' ) {
174
175 $section = new \Kirki\Section( $id );
176 $section->remove();
177
178 }
179
180 /**
181 * Create a new field.
182 *
183 * @static
184 * @access public
185 * @param string $config_id The configuration ID for this field.
186 * @param array $args The field arguments.
187 */
188 public static function add_field( $config_id, $args ) {
189
190 if ( doing_action( 'customize_register' ) ) {
191 _doing_it_wrong( __METHOD__, esc_html__( 'Kirki fields should not be added on customize_register. Please add them directly, or on init.', 'kirki' ), '3.0.10' );
192 }
193
194 parent::maybe_show_fontawesome_nag( $args );
195
196 // Early exit if 'type' is not defined.
197 if ( ! isset( $args['type'] ) ) {
198 return;
199 }
200
201 $args = self::migrate_css_vars( $args );
202
203 $str = str_replace( [ '-', '_' ], ' ', $args['type'] );
204 $classname = '\Kirki\Field\\' . str_replace( ' ', '_', ucwords( $str ) );
205
206 $config = Config::get_instance( $config_id )->get_config();
207 $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : $config_id;
208
209 unset( $config['id'] );
210
211 $args = wp_parse_args( $args, $config );
212
213 if ( class_exists( $classname ) ) {
214 unset( $args['type'] );
215 new $classname( $args );
216 return;
217 }
218
219 new Field( $config_id, $args );
220
221 }
222
223 /**
224 * Remove a control.
225 *
226 * @static
227 * @access public
228 * @since 3.0.17
229 * @param string $id The field ID.
230 */
231 public static function remove_control( $id ) {
232
233 if ( ! in_array( $id, self::$controls_to_remove, true ) ) {
234 self::$controls_to_remove[] = $id;
235 }
236
237 }
238
239 /**
240 * Gets a parameter for a config-id.
241 *
242 * @static
243 * @access public
244 * @since 3.0.10
245 * @param string $id The config-ID.
246 * @param string $param The parameter we want.
247 * @return string
248 */
249 public static function get_config_param( $id, $param ) {
250
251 if ( ! isset( self::$config[ $id ] ) || ! isset( self::$config[ $id ][ $param ] ) ) {
252 return '';
253 }
254
255 return self::$config[ $id ][ $param ];
256
257 }
258
259 /**
260 * Migrate css-variables to output argument.
261 *
262 * This only exists for backwards-compatibility with the deprecated css-vars argument.
263 *
264 * @static
265 * @since 4.0
266 * @param array $args The field arguments.
267 * @return array
268 */
269 private static function migrate_css_vars( $args ) {
270
271 // Convert css_vars to output args.
272 if ( isset( $args['css_vars'] ) ) {
273
274 if ( isset( $args['transport'] ) && 'postMessage' === $args['transport'] ) {
275 $args['transport'] = 'auto';
276 }
277
278 // Convert to properly-formatted arrays.
279 $args['css_vars'] = (array) $args['css_vars'];
280
281 if ( isset( $args['css_vars'][0] ) && is_string( $args['css_vars'][0] ) ) {
282 $args['css_vars'] = [ $args['css_vars'] ];
283 }
284
285 foreach ( $args['css_vars'] as $css_var ) {
286 $output = [
287 'element' => ':root',
288 'property' => $css_var[0],
289 ];
290 if ( isset( $css_var[1] ) ) {
291 $output['value_pattern'] = $css_var[1];
292 }
293 if ( isset( $css_var[2] ) ) {
294 $output['choice'] = $css_var[2];
295 }
296 $args['output'][] = $output;
297 }
298 }
299
300 return $args;
301
302 }
303
304 }
305