Passed
Push — main ( 137754...ffd9e1 )
by TARIQ
04:53
created
packages/kirki-framework/compatibility/src/deprecated/filters.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -2,111 +2,111 @@
 block discarded – undo
2 2
 // phpcs:ignoreFile
3 3
 
4 4
 add_filter( 'kirki_config', function( $args ) {
5
-	return apply_filters( 'kirki/config', $args );
5
+    return apply_filters( 'kirki/config', $args );
6 6
 }, 99 );
7 7
 
8 8
 add_filter( 'kirki_control_types', function( $args ) {
9
-	return apply_filters( 'kirki/control_types', $args );
9
+    return apply_filters( 'kirki/control_types', $args );
10 10
 }, 99 );
11 11
 
12 12
 add_filter( 'kirki_section_types', function( $args ) {
13
-	return apply_filters( 'kirki/section_types', $args );
13
+    return apply_filters( 'kirki/section_types', $args );
14 14
 }, 99 );
15 15
 
16 16
 add_filter( 'kirki_section_types_exclude', function( $args ) {
17
-	return apply_filters( 'kirki/section_types/exclude', $args );
17
+    return apply_filters( 'kirki/section_types/exclude', $args );
18 18
 }, 99 );
19 19
 
20 20
 add_filter( 'kirki_control_types_exclude', function( $args ) {
21
-	return apply_filters( 'kirki/control_types/exclude', $args );
21
+    return apply_filters( 'kirki/control_types/exclude', $args );
22 22
 }, 99 );
23 23
 
24 24
 add_filter( 'kirki_controls', function( $args ) {
25
-	return apply_filters( 'kirki/controls', $args );
25
+    return apply_filters( 'kirki/controls', $args );
26 26
 }, 99 );
27 27
 
28 28
 add_filter( 'kirki_fields', function( $args ) {
29
-	return apply_filters( 'kirki/fields', $args );
29
+    return apply_filters( 'kirki/fields', $args );
30 30
 }, 99 );
31 31
 
32 32
 add_filter( 'kirki_modules', function( $args ) {
33
-	return apply_filters( 'kirki/modules', $args );
33
+    return apply_filters( 'kirki/modules', $args );
34 34
 }, 99 );
35 35
 
36 36
 add_filter( 'kirki_panel_types', function( $args ) {
37
-	return apply_filters( 'kirki/panel_types', $args );
37
+    return apply_filters( 'kirki/panel_types', $args );
38 38
 }, 99 );
39 39
 
40 40
 add_filter( 'kirki_setting_types', function( $args ) {
41
-	return apply_filters( 'kirki/setting_types', $args );
41
+    return apply_filters( 'kirki/setting_types', $args );
42 42
 }, 99 );
43 43
 
44 44
 add_filter( 'kirki_variable', function( $args ) {
45
-	return apply_filters( 'kirki/variable', $args );
45
+    return apply_filters( 'kirki/variable', $args );
46 46
 }, 99 );
47 47
 
48 48
 add_filter( 'kirki_values_get_value', function( $arg1, $arg2 ) {
49
-	return apply_filters( 'kirki/values/get_value', $arg1, $arg2 );
49
+    return apply_filters( 'kirki/values/get_value', $arg1, $arg2 );
50 50
 }, 99, 2 );
51 51
 
52 52
 add_action( 'init', function() {
53
-	$config_ids = \Kirki\Compatibility\Config::get_config_ids();
54
-	global $kirki_deprecated_filters_iteration;
55
-	foreach ( $config_ids as $config_id ) {
56
-		foreach( array(
57
-			'/dynamic_css',
58
-			'/output/control-classnames',
59
-			'/css/skip_hidden',
60
-			'/styles',
61
-			'/output/property-classnames',
62
-			'/webfonts/skip_hidden',
63
-		) as $filter_suffix ) {
64
-			$kirki_deprecated_filters_iteration = array( $config_id, $filter_suffix );
65
-			add_filter( "kirki_{$config_id}_{$filter_suffix}", function( $args ) {
66
-				global $kirki_deprecated_filters_iteration;
67
-				$kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
68
-				return apply_filters( "kirki/{$kirki_deprecated_filters_iteration[0]}/{$kirki_deprecated_filters_iteration[1]}", $args );
69
-			}, 99 );
70
-			if ( false !== strpos( $kirki_deprecated_filters_iteration[1], '-' ) ) {
71
-				$kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
72
-				add_filter( "kirki_{$config_id}_{$filter_suffix}", function( $args ) {
73
-					global $kirki_deprecated_filters_iteration;
74
-					$kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
75
-					return apply_filters( "kirki/{$kirki_deprecated_filters_iteration[0]}/{$kirki_deprecated_filters_iteration[1]}", $args );
76
-				}, 99 );
77
-			}
78
-		}
79
-	}
53
+    $config_ids = \Kirki\Compatibility\Config::get_config_ids();
54
+    global $kirki_deprecated_filters_iteration;
55
+    foreach ( $config_ids as $config_id ) {
56
+        foreach( array(
57
+            '/dynamic_css',
58
+            '/output/control-classnames',
59
+            '/css/skip_hidden',
60
+            '/styles',
61
+            '/output/property-classnames',
62
+            '/webfonts/skip_hidden',
63
+        ) as $filter_suffix ) {
64
+            $kirki_deprecated_filters_iteration = array( $config_id, $filter_suffix );
65
+            add_filter( "kirki_{$config_id}_{$filter_suffix}", function( $args ) {
66
+                global $kirki_deprecated_filters_iteration;
67
+                $kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
68
+                return apply_filters( "kirki/{$kirki_deprecated_filters_iteration[0]}/{$kirki_deprecated_filters_iteration[1]}", $args );
69
+            }, 99 );
70
+            if ( false !== strpos( $kirki_deprecated_filters_iteration[1], '-' ) ) {
71
+                $kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
72
+                add_filter( "kirki_{$config_id}_{$filter_suffix}", function( $args ) {
73
+                    global $kirki_deprecated_filters_iteration;
74
+                    $kirki_deprecated_filters_iteration[1] = str_replace( '-', '_', $kirki_deprecated_filters_iteration[1] );
75
+                    return apply_filters( "kirki/{$kirki_deprecated_filters_iteration[0]}/{$kirki_deprecated_filters_iteration[1]}", $args );
76
+                }, 99 );
77
+            }
78
+        }
79
+    }
80 80
 }, 99 );
81 81
 
82 82
 add_filter( 'kirki_enqueue_google_fonts', function( $args ) {
83
-	return apply_filters( 'kirki/enqueue_google_fonts', $args );
83
+    return apply_filters( 'kirki/enqueue_google_fonts', $args );
84 84
 }, 99 );
85 85
 
86 86
 add_filter( 'kirki_styles_array', function( $args ) {
87
-	return apply_filters( 'kirki/styles_array', $args );
87
+    return apply_filters( 'kirki/styles_array', $args );
88 88
 }, 99 );
89 89
 
90 90
 add_filter( 'kirki_dynamic_css_method', function( $args ) {
91
-	return apply_filters( 'kirki/dynamic_css/method', $args );
91
+    return apply_filters( 'kirki/dynamic_css/method', $args );
92 92
 }, 99 );
93 93
 
94 94
 add_filter( 'kirki_postmessage_script', function( $args ) {
95
-	return apply_filters( 'kirki/postmessage/script', $args );
95
+    return apply_filters( 'kirki/postmessage/script', $args );
96 96
 }, 99 );
97 97
 
98 98
 add_filter( 'kirki_fonts_all', function( $args ) {
99
-	return apply_filters( 'kirki/fonts/all', $args );
99
+    return apply_filters( 'kirki/fonts/all', $args );
100 100
 }, 99 );
101 101
 
102 102
 add_filter( 'kirki_fonts_standard_fonts', function( $args ) {
103
-	return apply_filters( 'kirki/fonts/standard_fonts', $args );
103
+    return apply_filters( 'kirki/fonts/standard_fonts', $args );
104 104
 }, 99 );
105 105
 
106 106
 add_filter( 'kirki_fonts_google_fonts', function( $args ) {
107
-	return apply_filters( 'kirki/fonts/google_fonts', $args );
107
+    return apply_filters( 'kirki/fonts/google_fonts', $args );
108 108
 }, 99 );
109 109
 
110 110
 add_filter( 'kirki_googlefonts_load_method', function( $args ) {
111
-	return apply_filters( 'kirki/googlefonts_load_method', $args );
111
+    return apply_filters( 'kirki/googlefonts_load_method', $args );
112 112
 }, 99 );
Please login to merge, or discard this patch.
includes/kirki-4.0.24/packages/kirki-framework/compatibility/src/Config.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -16,164 +16,164 @@
 block discarded – undo
16 16
  */
17 17
 final class Config {
18 18
 
19
-	/**
20
-	 * Each instance is stored separately in this array.
21
-	 *
22
-	 * @static
23
-	 * @access private
24
-	 * @var array
25
-	 */
26
-	private static $instances = [];
27
-
28
-	/**
29
-	 * The finalized configuration array.
30
-	 *
31
-	 * @access protected
32
-	 * @var array
33
-	 */
34
-	protected $config_final = [];
35
-
36
-	/**
37
-	 * The configuration ID.
38
-	 *
39
-	 * @access public
40
-	 * @var string
41
-	 */
42
-	public $id = 'global';
43
-
44
-	/**
45
-	 * Capability (fields will inherit this).
46
-	 *
47
-	 * @access protected
48
-	 * @var string
49
-	 */
50
-	protected $capability = 'edit_theme_options';
51
-
52
-	/**
53
-	 * The data-type we'll be using.
54
-	 *
55
-	 * @access protected
56
-	 * @var string
57
-	 */
58
-	protected $option_type = 'theme_mod';
59
-
60
-	/**
61
-	 * If we're using serialized options, then this is the global option name.
62
-	 *
63
-	 * @access protected
64
-	 * @var string
65
-	 */
66
-	protected $option_name = '';
67
-
68
-	/**
69
-	 * The compiler.
70
-	 *
71
-	 * @access protected
72
-	 * @var array
73
-	 */
74
-	protected $compiler = [];
75
-
76
-	/**
77
-	 * Set to true if you want to completely disable any Kirki-generated CSS.
78
-	 *
79
-	 * @access protected
80
-	 * @var bool
81
-	 */
82
-	protected $disable_output = false;
83
-
84
-	/**
85
-	 * The class constructor.
86
-	 * Use the get_instance() static method to get the instance you need.
87
-	 *
88
-	 * @access private
89
-	 * @param string $config_id @see Kirki\Compatibility\Config::get_instance().
90
-	 * @param array  $args      @see Kirki\Compatibility\Config::get_instance().
91
-	 */
92
-	private function __construct( $config_id = 'global', $args = [] ) {
93
-
94
-		// Get defaults from the class.
95
-		$defaults = get_class_vars( __CLASS__ );
96
-		// Skip what we don't need in this context.
97
-		unset( $defaults['config_final'] );
98
-		unset( $defaults['instances'] );
99
-		// Apply any kirki_config global filters.
100
-		$defaults = apply_filters( 'kirki_config', $defaults );
101
-		// Merge our args with the defaults.
102
-		$args = wp_parse_args( $args, $defaults );
103
-
104
-		// Modify default values with the defined ones.
105
-		foreach ( $args as $key => $value ) {
106
-			// Is this property whitelisted?
107
-			if ( property_exists( $this, $key ) ) {
108
-				$args[ $key ] = $value;
109
-			}
110
-		}
111
-		$this->id = $config_id;
112
-
113
-		$this->config_final = wp_parse_args(
114
-			[
115
-				'id' => $config_id,
116
-			],
117
-			$args
118
-		);
119
-	}
120
-
121
-	/**
122
-	 * Use this method to get an instance of your config.
123
-	 * Each config has its own instance of this object.
124
-	 *
125
-	 * @static
126
-	 * @access public
127
-	 * @param string $id     Config ID.
128
-	 * @param array  $args   {
129
-	 * Optional. Arguments to override config defaults.
130
-	 *
131
-	 *    @type string      $capability       @see https://codex.wordpress.org/Roles_and_Capabilities
132
-	 *    @type string      $option_type      theme_mod or option.
133
-	 *    @type string      $option_name      If we want to used serialized options,
134
-	 *                                        this is where we'll be adding the option name.
135
-	 *                                        All fields using this config will be items in that array.
136
-	 *    @type array       $compiler         Not yet fully implemented
137
-	 *    @type bool        $disable_output   If set to true, no CSS will be generated
138
-	 *                                        from fields using this configuration.
139
-	 * }
140
-	 *
141
-	 * @return Kirki\Compatibility\Config
142
-	 */
143
-	public static function get_instance( $id = 'global', $args = [] ) {
144
-		if ( empty( $id ) ) {
145
-			$id = 'global';
146
-		}
147
-		$id_md5 = md5( $id );
148
-		if ( ! isset( self::$instances[ $id_md5 ] ) ) {
149
-			self::$instances[ $id_md5 ] = new self( $id, $args );
150
-		}
151
-		return self::$instances[ $id_md5 ];
152
-	}
153
-
154
-	/**
155
-	 * Get the IDs of all current configs.
156
-	 *
157
-	 * @static
158
-	 * @access public
159
-	 * @since 3.0.22
160
-	 * @return array
161
-	 */
162
-	public static function get_config_ids() {
163
-		$configs = [];
164
-		foreach ( self::$instances as $instance ) {
165
-			$configs[] = $instance->id;
166
-		}
167
-		return array_unique( $configs );
168
-	}
169
-
170
-	/**
171
-	 * Returns the $config_final property
172
-	 *
173
-	 * @access public
174
-	 * @return array
175
-	 */
176
-	public function get_config() {
177
-		return $this->config_final;
178
-	}
19
+    /**
20
+     * Each instance is stored separately in this array.
21
+     *
22
+     * @static
23
+     * @access private
24
+     * @var array
25
+     */
26
+    private static $instances = [];
27
+
28
+    /**
29
+     * The finalized configuration array.
30
+     *
31
+     * @access protected
32
+     * @var array
33
+     */
34
+    protected $config_final = [];
35
+
36
+    /**
37
+     * The configuration ID.
38
+     *
39
+     * @access public
40
+     * @var string
41
+     */
42
+    public $id = 'global';
43
+
44
+    /**
45
+     * Capability (fields will inherit this).
46
+     *
47
+     * @access protected
48
+     * @var string
49
+     */
50
+    protected $capability = 'edit_theme_options';
51
+
52
+    /**
53
+     * The data-type we'll be using.
54
+     *
55
+     * @access protected
56
+     * @var string
57
+     */
58
+    protected $option_type = 'theme_mod';
59
+
60
+    /**
61
+     * If we're using serialized options, then this is the global option name.
62
+     *
63
+     * @access protected
64
+     * @var string
65
+     */
66
+    protected $option_name = '';
67
+
68
+    /**
69
+     * The compiler.
70
+     *
71
+     * @access protected
72
+     * @var array
73
+     */
74
+    protected $compiler = [];
75
+
76
+    /**
77
+     * Set to true if you want to completely disable any Kirki-generated CSS.
78
+     *
79
+     * @access protected
80
+     * @var bool
81
+     */
82
+    protected $disable_output = false;
83
+
84
+    /**
85
+     * The class constructor.
86
+     * Use the get_instance() static method to get the instance you need.
87
+     *
88
+     * @access private
89
+     * @param string $config_id @see Kirki\Compatibility\Config::get_instance().
90
+     * @param array  $args      @see Kirki\Compatibility\Config::get_instance().
91
+     */
92
+    private function __construct( $config_id = 'global', $args = [] ) {
93
+
94
+        // Get defaults from the class.
95
+        $defaults = get_class_vars( __CLASS__ );
96
+        // Skip what we don't need in this context.
97
+        unset( $defaults['config_final'] );
98
+        unset( $defaults['instances'] );
99
+        // Apply any kirki_config global filters.
100
+        $defaults = apply_filters( 'kirki_config', $defaults );
101
+        // Merge our args with the defaults.
102
+        $args = wp_parse_args( $args, $defaults );
103
+
104
+        // Modify default values with the defined ones.
105
+        foreach ( $args as $key => $value ) {
106
+            // Is this property whitelisted?
107
+            if ( property_exists( $this, $key ) ) {
108
+                $args[ $key ] = $value;
109
+            }
110
+        }
111
+        $this->id = $config_id;
112
+
113
+        $this->config_final = wp_parse_args(
114
+            [
115
+                'id' => $config_id,
116
+            ],
117
+            $args
118
+        );
119
+    }
120
+
121
+    /**
122
+     * Use this method to get an instance of your config.
123
+     * Each config has its own instance of this object.
124
+     *
125
+     * @static
126
+     * @access public
127
+     * @param string $id     Config ID.
128
+     * @param array  $args   {
129
+     * Optional. Arguments to override config defaults.
130
+     *
131
+     *    @type string      $capability       @see https://codex.wordpress.org/Roles_and_Capabilities
132
+     *    @type string      $option_type      theme_mod or option.
133
+     *    @type string      $option_name      If we want to used serialized options,
134
+     *                                        this is where we'll be adding the option name.
135
+     *                                        All fields using this config will be items in that array.
136
+     *    @type array       $compiler         Not yet fully implemented
137
+     *    @type bool        $disable_output   If set to true, no CSS will be generated
138
+     *                                        from fields using this configuration.
139
+     * }
140
+     *
141
+     * @return Kirki\Compatibility\Config
142
+     */
143
+    public static function get_instance( $id = 'global', $args = [] ) {
144
+        if ( empty( $id ) ) {
145
+            $id = 'global';
146
+        }
147
+        $id_md5 = md5( $id );
148
+        if ( ! isset( self::$instances[ $id_md5 ] ) ) {
149
+            self::$instances[ $id_md5 ] = new self( $id, $args );
150
+        }
151
+        return self::$instances[ $id_md5 ];
152
+    }
153
+
154
+    /**
155
+     * Get the IDs of all current configs.
156
+     *
157
+     * @static
158
+     * @access public
159
+     * @since 3.0.22
160
+     * @return array
161
+     */
162
+    public static function get_config_ids() {
163
+        $configs = [];
164
+        foreach ( self::$instances as $instance ) {
165
+            $configs[] = $instance->id;
166
+        }
167
+        return array_unique( $configs );
168
+    }
169
+
170
+    /**
171
+     * Returns the $config_final property
172
+     *
173
+     * @access public
174
+     * @return array
175
+     */
176
+    public function get_config() {
177
+        return $this->config_final;
178
+    }
179 179
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/compatibility/src/Settings.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -17,141 +17,141 @@
 block discarded – undo
17 17
  */
18 18
 class Settings {
19 19
 
20
-	/**
21
-	 * The global $wp_customize object.
22
-	 *
23
-	 * @access protected
24
-	 * @var WP_Customize_Manager
25
-	 */
26
-	protected $wp_customize;
27
-
28
-	/**
29
-	 * The setting-stypes we're using.
30
-	 *
31
-	 * @access protected
32
-	 * @var array
33
-	 */
34
-	protected $setting_types = [];
35
-
36
-	/**
37
-	 * Creates a new Settings object.
38
-	 * Class constructor.
39
-	 *
40
-	 * @access public
41
-	 * @param array $args The field definition as sanitized in Kirki\Compatibility\Field.
42
-	 */
43
-	public function __construct( $args = [] ) {
44
-
45
-		// Set the $wp_customize property.
46
-		global $wp_customize;
47
-		if ( ! $wp_customize ) {
48
-			return;
49
-		}
50
-		$this->wp_customize = $wp_customize;
51
-
52
-		// Set the setting_types.
53
-		$this->set_setting_types();
54
-
55
-		// Add the settings.
56
-		$this->add_settings( $args );
57
-
58
-	}
59
-
60
-	/**
61
-	 * Adds the settings for this field.
62
-	 * If settings are defined as an array, then it goes through them
63
-	 * and calls the add_setting method.
64
-	 * If not an array, then it just calls add_setting
65
-	 *
66
-	 * @access private
67
-	 * @param array $args The field definition as sanitized in Kirki\Compatibility\Field.
68
-	 */
69
-	final function add_settings( $args = [] ) {
70
-
71
-		// Get the classname we'll be using to create our setting(s).
72
-		$classname = false;
73
-		if ( isset( $args['option_type'] ) && array_key_exists( $args['option_type'], $this->setting_types ) ) {
74
-			$classname = $this->setting_types[ $args['option_type'] ];
75
-		}
76
-		if ( ! isset( $args['type'] ) || ! array_key_exists( $args['type'], $this->setting_types ) ) {
77
-			$args['type'] = 'default';
78
-		}
79
-		$classname = ! $classname ? $this->setting_types[ $args['type'] ] : $classname;
80
-
81
-		// If settings are defined as an array, then we need to go through them
82
-		// and call add_setting for each one of them separately.
83
-		if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) {
84
-
85
-			// Make sure defaults have been defined.
86
-			if ( ! isset( $args['default'] ) || ! is_array( $args['default'] ) ) {
87
-				$args['default'] = [];
88
-			}
89
-			foreach ( $args['settings'] as $key => $value ) {
90
-				// ? Bagus: this $defaults var is not defined anywhere inside this function, so is this a mistake?
91
-				$default = ( isset( $defaults[ $key ] ) ) ? $defaults[ $key ] : '';
92
-				$this->add_setting( $classname, $value, $default, $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] );
93
-			}
94
-		}
95
-		$this->add_setting( $classname, $args['settings'], $args['default'], $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] );
96
-	}
97
-
98
-	/**
99
-	 * This is where we're finally adding the setting to the Customizer.
100
-	 *
101
-	 * @access private
102
-	 * @param string       $classname           The name of the class that will be used to create this setting.
103
-	 *                                          We're getting this from $this->setting_types.
104
-	 * @param string       $setting             The setting-name.
105
-	 *                                          If settings is an array, then this method is called per-setting.
106
-	 * @param string|array $default             Default value for this setting.
107
-	 * @param string       $type                The data type we're using. Valid options: theme_mod|option.
108
-	 * @param string       $capability          @see https://codex.wordpress.org/Roles_and_Capabilities.
109
-	 * @param string       $transport           Use refresh|postMessage.
110
-	 * @param string|array $sanitize_callback   A callable sanitization function or method.
111
-	 */
112
-	final function add_setting( $classname, $setting, $default, $type, $capability, $transport, $sanitize_callback ) {
113
-
114
-		$this->wp_customize->add_setting(
115
-			new $classname(
116
-				$this->wp_customize,
117
-				$setting,
118
-				[
119
-					'default'           => $default,
120
-					'type'              => $type,
121
-					'capability'        => $capability,
122
-					'transport'         => $transport,
123
-					'sanitize_callback' => $sanitize_callback,
124
-				]
125
-			)
126
-		);
127
-
128
-	}
129
-
130
-	/**
131
-	 * Sets the $this->setting_types property.
132
-	 * Makes sure the kirki_setting_types filter is applied
133
-	 * and that the defined classes actually exist.
134
-	 * If a defined class does not exist, it is removed.
135
-	 */
136
-	final function set_setting_types() {
137
-
138
-		// Apply the kirki_setting_types filter.
139
-		$this->setting_types = apply_filters(
140
-			'kirki_setting_types',
141
-			[
142
-				'default'     => 'WP_Customize_Setting',
143
-				'repeater'    => '\Kirki_Settings_Repeater_Setting',
144
-				'user_meta'   => '\Kirki\Util\Setting\User_Meta',
145
-				'site_option' => '\Kirki\Util\Setting\Site_Option',
146
-			]
147
-		);
148
-
149
-		// Make sure the defined classes actually exist.
150
-		foreach ( $this->setting_types as $key => $classname ) {
151
-
152
-			if ( ! class_exists( $classname ) ) {
153
-				unset( $this->setting_types[ $key ] );
154
-			}
155
-		}
156
-	}
20
+    /**
21
+     * The global $wp_customize object.
22
+     *
23
+     * @access protected
24
+     * @var WP_Customize_Manager
25
+     */
26
+    protected $wp_customize;
27
+
28
+    /**
29
+     * The setting-stypes we're using.
30
+     *
31
+     * @access protected
32
+     * @var array
33
+     */
34
+    protected $setting_types = [];
35
+
36
+    /**
37
+     * Creates a new Settings object.
38
+     * Class constructor.
39
+     *
40
+     * @access public
41
+     * @param array $args The field definition as sanitized in Kirki\Compatibility\Field.
42
+     */
43
+    public function __construct( $args = [] ) {
44
+
45
+        // Set the $wp_customize property.
46
+        global $wp_customize;
47
+        if ( ! $wp_customize ) {
48
+            return;
49
+        }
50
+        $this->wp_customize = $wp_customize;
51
+
52
+        // Set the setting_types.
53
+        $this->set_setting_types();
54
+
55
+        // Add the settings.
56
+        $this->add_settings( $args );
57
+
58
+    }
59
+
60
+    /**
61
+     * Adds the settings for this field.
62
+     * If settings are defined as an array, then it goes through them
63
+     * and calls the add_setting method.
64
+     * If not an array, then it just calls add_setting
65
+     *
66
+     * @access private
67
+     * @param array $args The field definition as sanitized in Kirki\Compatibility\Field.
68
+     */
69
+    final function add_settings( $args = [] ) {
70
+
71
+        // Get the classname we'll be using to create our setting(s).
72
+        $classname = false;
73
+        if ( isset( $args['option_type'] ) && array_key_exists( $args['option_type'], $this->setting_types ) ) {
74
+            $classname = $this->setting_types[ $args['option_type'] ];
75
+        }
76
+        if ( ! isset( $args['type'] ) || ! array_key_exists( $args['type'], $this->setting_types ) ) {
77
+            $args['type'] = 'default';
78
+        }
79
+        $classname = ! $classname ? $this->setting_types[ $args['type'] ] : $classname;
80
+
81
+        // If settings are defined as an array, then we need to go through them
82
+        // and call add_setting for each one of them separately.
83
+        if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) {
84
+
85
+            // Make sure defaults have been defined.
86
+            if ( ! isset( $args['default'] ) || ! is_array( $args['default'] ) ) {
87
+                $args['default'] = [];
88
+            }
89
+            foreach ( $args['settings'] as $key => $value ) {
90
+                // ? Bagus: this $defaults var is not defined anywhere inside this function, so is this a mistake?
91
+                $default = ( isset( $defaults[ $key ] ) ) ? $defaults[ $key ] : '';
92
+                $this->add_setting( $classname, $value, $default, $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] );
93
+            }
94
+        }
95
+        $this->add_setting( $classname, $args['settings'], $args['default'], $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] );
96
+    }
97
+
98
+    /**
99
+     * This is where we're finally adding the setting to the Customizer.
100
+     *
101
+     * @access private
102
+     * @param string       $classname           The name of the class that will be used to create this setting.
103
+     *                                          We're getting this from $this->setting_types.
104
+     * @param string       $setting             The setting-name.
105
+     *                                          If settings is an array, then this method is called per-setting.
106
+     * @param string|array $default             Default value for this setting.
107
+     * @param string       $type                The data type we're using. Valid options: theme_mod|option.
108
+     * @param string       $capability          @see https://codex.wordpress.org/Roles_and_Capabilities.
109
+     * @param string       $transport           Use refresh|postMessage.
110
+     * @param string|array $sanitize_callback   A callable sanitization function or method.
111
+     */
112
+    final function add_setting( $classname, $setting, $default, $type, $capability, $transport, $sanitize_callback ) {
113
+
114
+        $this->wp_customize->add_setting(
115
+            new $classname(
116
+                $this->wp_customize,
117
+                $setting,
118
+                [
119
+                    'default'           => $default,
120
+                    'type'              => $type,
121
+                    'capability'        => $capability,
122
+                    'transport'         => $transport,
123
+                    'sanitize_callback' => $sanitize_callback,
124
+                ]
125
+            )
126
+        );
127
+
128
+    }
129
+
130
+    /**
131
+     * Sets the $this->setting_types property.
132
+     * Makes sure the kirki_setting_types filter is applied
133
+     * and that the defined classes actually exist.
134
+     * If a defined class does not exist, it is removed.
135
+     */
136
+    final function set_setting_types() {
137
+
138
+        // Apply the kirki_setting_types filter.
139
+        $this->setting_types = apply_filters(
140
+            'kirki_setting_types',
141
+            [
142
+                'default'     => 'WP_Customize_Setting',
143
+                'repeater'    => '\Kirki_Settings_Repeater_Setting',
144
+                'user_meta'   => '\Kirki\Util\Setting\User_Meta',
145
+                'site_option' => '\Kirki\Util\Setting\Site_Option',
146
+            ]
147
+        );
148
+
149
+        // Make sure the defined classes actually exist.
150
+        foreach ( $this->setting_types as $key => $classname ) {
151
+
152
+            if ( ! class_exists( $classname ) ) {
153
+                unset( $this->setting_types[ $key ] );
154
+            }
155
+        }
156
+    }
157 157
 }
Please login to merge, or discard this patch.
includes/kirki-4.0.24/packages/kirki-framework/compatibility/src/Field.php 1 patch
Indentation   +654 added lines, -654 removed lines patch added patch discarded remove patch
@@ -20,658 +20,658 @@
 block discarded – undo
20 20
  */
21 21
 class Field {
22 22
 
23
-	/**
24
-	 * An array of the field arguments.
25
-	 *
26
-	 * @access protected
27
-	 * @var array
28
-	 */
29
-	protected $args = [];
30
-
31
-	/**
32
-	 * The ID of the kirki_config we're using.
33
-	 *
34
-	 * @see Kirki\Compatibility\Config
35
-	 * @access protected
36
-	 * @var string
37
-	 */
38
-	protected $kirki_config = 'global';
39
-
40
-	/**
41
-	 * The capability required so that users can edit this field.
42
-	 *
43
-	 * @access protected
44
-	 * @var string
45
-	 */
46
-	protected $capability = 'edit_theme_options';
47
-
48
-	/**
49
-	 * If we're using options instead of theme_mods
50
-	 * and we want them serialized, this is the option that
51
-	 * will saved in the db.
52
-	 *
53
-	 * @access protected
54
-	 * @var string
55
-	 */
56
-	protected $option_name = '';
57
-
58
-	/**
59
-	 * Custom input attributes (defined as an array).
60
-	 *
61
-	 * @access protected
62
-	 * @var array
63
-	 */
64
-	protected $input_attrs = [];
65
-
66
-	/**
67
-	 * Preset choices.
68
-	 *
69
-	 * @access protected
70
-	 * @var array
71
-	 */
72
-	protected $preset = [];
73
-
74
-	/**
75
-	 * CSS Variables.
76
-	 *
77
-	 * @access protected
78
-	 * @var array
79
-	 */
80
-	protected $css_vars = [];
81
-
82
-	/**
83
-	 * Use "theme_mod" or "option".
84
-	 *
85
-	 * @access protected
86
-	 * @var string
87
-	 */
88
-	protected $option_type = 'theme_mod';
89
-
90
-	/**
91
-	 * The name of this setting (id for the db).
92
-	 *
93
-	 * @access protected
94
-	 * @var string|array
95
-	 */
96
-	protected $settings = '';
97
-
98
-	/**
99
-	 * Set to true if you want to disable all CSS output for this field.
100
-	 *
101
-	 * @access protected
102
-	 * @var bool
103
-	 */
104
-	protected $disable_output = false;
105
-
106
-	/**
107
-	 * The field type.
108
-	 *
109
-	 * @access protected
110
-	 * @var string
111
-	 */
112
-	protected $type = 'kirki-generic';
113
-
114
-	/**
115
-	 * Some fields require options to be set.
116
-	 * We're whitelisting the property here
117
-	 * and suggest you validate this in a child class.
118
-	 *
119
-	 * @access protected
120
-	 * @var array
121
-	 */
122
-	protected $choices = [];
123
-
124
-	/**
125
-	 * Assign this field to a section.
126
-	 * Fields not assigned to a section will not be displayed in the customizer.
127
-	 *
128
-	 * @access protected
129
-	 * @var string
130
-	 */
131
-	protected $section = '';
132
-
133
-	/**
134
-	 * The default value for this field.
135
-	 *
136
-	 * @access protected
137
-	 * @var string|array|bool
138
-	 */
139
-	protected $default = '';
140
-
141
-	/**
142
-	 * Priority determines the position of a control inside a section.
143
-	 * Lower priority numbers move the control to the top.
144
-	 *
145
-	 * @access protected
146
-	 * @var int
147
-	 */
148
-	protected $priority = 10;
149
-
150
-	/**
151
-	 * Unique ID for this field.
152
-	 * This is auto-calculated from the $settings argument.
153
-	 *
154
-	 * @access protected
155
-	 * @var string
156
-	 */
157
-	protected $id = '';
158
-
159
-	/**
160
-	 * Use if you want to automatically generate CSS from this field's value.
161
-	 *
162
-	 * @see https://kirki.org/docs/arguments/output
163
-	 * @access protected
164
-	 * @var array
165
-	 */
166
-	protected $output = [];
167
-
168
-	/**
169
-	 * Use to automatically generate postMessage scripts.
170
-	 * Not necessary to use if you use 'transport' => 'auto'
171
-	 * and have already set an array for the 'output' argument.
172
-	 *
173
-	 * @see https://kirki.org/docs/arguments/js_vars
174
-	 * @access protected
175
-	 * @var array
176
-	 */
177
-	protected $js_vars = [];
178
-
179
-	/**
180
-	 * If you want to use a CSS compiler, then use this to set the variable names.
181
-	 *
182
-	 * @see https://kirki.org/docs/arguments/variables
183
-	 * @access protected
184
-	 * @var array
185
-	 */
186
-	protected $variables = [];
187
-
188
-	/**
189
-	 * Text that will be used in a tooltip to provide extra info for this field.
190
-	 *
191
-	 * @access protected
192
-	 * @var string
193
-	 */
194
-	protected $tooltip = '';
195
-
196
-	/**
197
-	 * A custom callback to determine if the field should be visible or not.
198
-	 *
199
-	 * @access protected
200
-	 * @var string|array
201
-	 */
202
-	protected $active_callback = '__return_true';
203
-
204
-	/**
205
-	 * A custom sanitize callback that will be used to properly save the values.
206
-	 *
207
-	 * @access protected
208
-	 * @var string|array
209
-	 */
210
-	protected $sanitize_callback = '';
211
-
212
-	/**
213
-	 * Use 'refresh', 'postMessage' or 'auto'.
214
-	 * 'auto' will automatically geberate any 'js_vars' from the 'output' argument.
215
-	 *
216
-	 * @access protected
217
-	 * @var string
218
-	 */
219
-	protected $transport = 'refresh';
220
-
221
-	/**
222
-	 * Define dependencies to show/hide this field based on the values of other fields.
223
-	 *
224
-	 * @access protected
225
-	 * @var array
226
-	 */
227
-	protected $required = [];
228
-
229
-	/**
230
-	 * Partial Refreshes array.
231
-	 *
232
-	 * @access protected
233
-	 * @var array
234
-	 */
235
-	protected $partial_refresh = [];
236
-
237
-	/**
238
-	 * The class constructor.
239
-	 * Parses and sanitizes all field arguments.
240
-	 * Then it adds the field to Kirki::$fields.
241
-	 *
242
-	 * @access public
243
-	 * @param string $config_id    The ID of the config we want to use.
244
-	 *                             Defaults to "global".
245
-	 *                             Configs are handled by the Kirki\Compatibility\Config class.
246
-	 * @param array  $args         The arguments of the field.
247
-	 */
248
-	public function __construct( $config_id = 'global', $args = [] ) {
249
-
250
-		/**
251
-		 * In case the user only provides 1 argument,
252
-		 * assume that the provided argument is $args and set $config_id = 'global'.
253
-		 */
254
-		if ( is_array( $config_id ) && empty( $args ) ) {
255
-			$args      = $config_id;
256
-			$config_id = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
257
-		}
258
-
259
-		if ( isset( $args['setting'] ) && ! empty( $args['setting'] ) && ( ! isset( $args['settings'] ) || empty( $args['settings'] ) ) ) {
260
-			/* translators: %s represents the field ID where the error occurs. */
261
-			_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Typo found in field %s - setting instead of settings.', 'kirki' ), esc_html( $args['settings'] ) ), '3.0.10' );
262
-			$args['settings'] = $args['setting'];
263
-			unset( $args['setting'] );
264
-		}
265
-
266
-		$args['kirki_config'] = $config_id;
267
-
268
-		$this->kirki_config = $config_id;
269
-
270
-		if ( '' === $config_id ) {
271
-			/* translators: %1$s represents the field ID where the error occurs. %2$s is the URL in the documentation site. */
272
-			_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Config not defined for field %1$s - See %2$s for details on how to properly add fields.', 'kirki' ), esc_html( $args['settings'] ), 'https://aristath.github.io/kirki/docs/getting-started/fields.html' ), '3.0.10' );
273
-			$this->kirki_config = 'global';
274
-		}
275
-
276
-		// Get defaults from the class.
277
-		$defaults = get_class_vars( __CLASS__ );
278
-
279
-		// Get the config arguments, and merge them with the defaults.
280
-		$config_defaults = ( isset( Kirki::$config['global'] ) ) ? Kirki::$config['global'] : [];
281
-
282
-		if ( 'global' !== $this->kirki_config && isset( Kirki::$config[ $this->kirki_config ] ) ) {
283
-			$config_defaults = Kirki::$config[ $this->kirki_config ];
284
-		}
285
-
286
-		$config_defaults = ( is_array( $config_defaults ) ) ? $config_defaults : [];
287
-
288
-		foreach ( $config_defaults as $key => $value ) {
289
-			if ( isset( $defaults[ $key ] ) && ! empty( $value ) && $value !== $defaults[ $key ] ) {
290
-				$defaults[ $key ] = $value;
291
-			}
292
-		}
293
-
294
-		// Merge our args with the defaults.
295
-		$args = wp_parse_args( $args, $defaults );
296
-
297
-		// Set the class properties using the parsed args.
298
-		foreach ( $args as $key => $value ) {
299
-			$this->$key = $value;
300
-		}
301
-
302
-		$this->args = $args;
303
-
304
-		$this->set_field();
305
-
306
-		// Instantiate the \Kirki\Field to apply hooks.
307
-		new \Kirki\Field\None( $this->args );
308
-
309
-	}
310
-
311
-	/**
312
-	 * Processes the field arguments
313
-	 *
314
-	 * @access protected
315
-	 */
316
-	protected function set_field() {
317
-
318
-		$properties = get_class_vars( __CLASS__ );
319
-
320
-		// Some things must run before the others.
321
-		$this->set_option_type();
322
-		$this->set_settings();
323
-
324
-		// Sanitize the properties, skipping the ones that have already run above.
325
-		foreach ( array_keys( $properties ) as $property ) {
326
-			if ( in_array( $property, [ 'option_name', 'option_type', 'settings' ], true ) ) {
327
-				continue;
328
-			}
329
-			if ( method_exists( $this, 'set_' . $property ) ) {
330
-				$method_name = 'set_' . $property;
331
-				$this->$method_name();
332
-			}
333
-		}
334
-
335
-		// Get all arguments with their values.
336
-		$args = get_object_vars( $this );
337
-
338
-		foreach ( array_keys( $args ) as $key ) {
339
-			$args[ $key ] = $this->$key;
340
-		}
341
-
342
-		// Add the field to the static $fields variable properly indexed.
343
-		Kirki::$fields[ $this->settings ] = $args;
344
-
345
-	}
346
-
347
-	/**
348
-	 * Escape the $section.
349
-	 *
350
-	 * @access protected
351
-	 */
352
-	protected function set_input_attrs() {
353
-		$this->input_attrs = (array) $this->input_attrs;
354
-	}
355
-
356
-	/**
357
-	 * Make sure we're using the correct option_type
358
-	 *
359
-	 * @access protected
360
-	 */
361
-	protected function set_option_type() {
362
-
363
-		// Take care of common typos.
364
-		if ( 'options' === $this->option_type ) {
365
-			$this->option_type = 'option';
366
-		}
367
-
368
-		// Take care of common typos.
369
-		if ( 'theme_mods' === $this->option_type ) {
370
-			/* translators: %1$s represents the field ID where the error occurs. */
371
-			_doing_it_wrong( __METHOD__, sprintf( esc_html( 'Typo found in field %s - "theme_mods" vs "theme_mod"', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
372
-			$this->option_type = 'theme_mod';
373
-		}
374
-	}
375
-
376
-	/**
377
-	 * Modifications for partial refreshes.
378
-	 *
379
-	 * @access protected
380
-	 */
381
-	protected function set_partial_refresh() {
382
-		if ( ! is_array( $this->partial_refresh ) ) {
383
-			$this->partial_refresh = [];
384
-		}
385
-		foreach ( $this->partial_refresh as $id => $args ) {
386
-			if ( ! is_array( $args ) || ! isset( $args['selector'] ) || ! isset( $args['render_callback'] ) || ! is_callable( $args['render_callback'] ) ) {
387
-				/* translators: %1$s represents the field ID where the error occurs. */
388
-				_doing_it_wrong( __METHOD__, sprintf( esc_html__( '"partial_refresh" invalid entry in field %s', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
389
-				unset( $this->partial_refresh[ $id ] );
390
-				continue;
391
-			}
392
-		}
393
-		if ( ! empty( $this->partial_refresh ) ) {
394
-			$this->transport = 'postMessage';
395
-		}
396
-	}
397
-
398
-	/**
399
-	 * Sets the settings.
400
-	 * If we're using serialized options it makes sure that settings are properly formatted.
401
-	 * We'll also be escaping all setting names here for consistency.
402
-	 *
403
-	 * @access protected
404
-	 */
405
-	protected function set_settings() {
406
-
407
-		// If settings is not an array, temporarily convert it to an array.
408
-		// This is just to allow us to process everything the same way and avoid code duplication.
409
-		// if settings is not an array then it will not be set as an array in the end.
410
-		if ( ! is_array( $this->settings ) ) {
411
-			$this->settings = [
412
-				'kirki_placeholder_setting' => $this->settings,
413
-			];
414
-		}
415
-		$settings = [];
416
-		foreach ( $this->settings as $setting_key => $setting_value ) {
417
-			$settings[ $setting_key ] = $setting_value;
418
-
419
-			// If we're using serialized options then we need to spice this up.
420
-			if ( 'option' === $this->option_type && '' !== $this->option_name && ( false === strpos( $setting_key, '[' ) ) ) {
421
-				$settings[ $setting_key ] = "{$this->option_name}[{$setting_value}]";
422
-			}
423
-		}
424
-		$this->settings = $settings;
425
-		if ( isset( $this->settings['kirki_placeholder_setting'] ) ) {
426
-			$this->settings = $this->settings['kirki_placeholder_setting'];
427
-		}
428
-	}
429
-
430
-	/**
431
-	 * Sets the active_callback
432
-	 * If we're using the $required argument,
433
-	 * Then this is where the switch is made to our evaluation method.
434
-	 *
435
-	 * @access protected
436
-	 */
437
-	protected function set_active_callback() {
438
-
439
-		if ( is_array( $this->active_callback ) ) {
440
-
441
-			if ( ! is_callable( $this->active_callback ) ) {
442
-
443
-				// Bugfix for https://github.com/aristath/kirki/issues/1961.
444
-				foreach ( $this->active_callback as $key => $val ) {
445
-					if ( is_callable( $val ) ) {
446
-						unset( $this->active_callback[ $key ] );
447
-					}
448
-				}
449
-				if ( isset( $this->active_callback[0] ) ) {
450
-					$this->required = $this->active_callback;
451
-				}
452
-			}
453
-		}
454
-
455
-		if ( ! empty( $this->required ) ) {
456
-			$this->active_callback = '__return_true';
457
-			return;
458
-		}
459
-		// No need to proceed any further if we're using the default value.
460
-		if ( '__return_true' === $this->active_callback ) {
461
-			return;
462
-		}
463
-
464
-		// Make sure the function is callable, otherwise fallback to __return_true.
465
-		if ( ! is_callable( $this->active_callback ) ) {
466
-			$this->active_callback = '__return_true';
467
-		}
468
-
469
-	}
470
-
471
-	/**
472
-	 * Sets the $id.
473
-	 * Setting the ID should happen after the 'settings' sanitization.
474
-	 * This way we can also properly handle cases where the option_type is set to 'option'
475
-	 * and we're using an array instead of individual options.
476
-	 *
477
-	 * @access protected
478
-	 */
479
-	protected function set_id() {
480
-		$this->id = sanitize_key( str_replace( '[', '-', str_replace( ']', '', $this->settings ) ) );
481
-	}
482
-
483
-	/**
484
-	 * Sets the $choices.
485
-	 *
486
-	 * @access protected
487
-	 */
488
-	protected function set_choices() {
489
-		if ( ! is_array( $this->choices ) ) {
490
-			$this->choices = [];
491
-		}
492
-	}
493
-
494
-	/**
495
-	 * Escapes the $disable_output.
496
-	 *
497
-	 * @access protected
498
-	 */
499
-	protected function set_disable_output() {
500
-		$this->disable_output = (bool) $this->disable_output;
501
-	}
502
-
503
-	/**
504
-	 * Sets the $sanitize_callback
505
-	 *
506
-	 * @access protected
507
-	 */
508
-	protected function set_output() {
509
-		if ( empty( $this->output ) ) {
510
-			return;
511
-		}
512
-		if ( ! is_array( $this->output ) ) {
513
-			/* translators: The field ID where the error occurs. */
514
-			_doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
515
-			$this->output = [
516
-				[
517
-					'element' => $this->output,
518
-				],
519
-			];
520
-		}
521
-
522
-		// Convert to array of arrays if needed.
523
-		if ( isset( $this->output['element'] ) ) {
524
-			/* translators: The field ID where the error occurs. */
525
-			_doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
526
-			$this->output = [ $this->output ];
527
-		}
528
-
529
-		foreach ( $this->output as $key => $output ) {
530
-			if ( empty( $output ) || ! isset( $output['element'] ) ) {
531
-				unset( $this->output[ $key ] );
532
-				continue;
533
-			}
534
-			if ( ! isset( $output['sanitize_callback'] ) && isset( $output['callback'] ) ) {
535
-				$this->output[ $key ]['sanitize_callback'] = $output['callback'];
536
-			}
537
-
538
-			// Convert element arrays to strings.
539
-			if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
540
-				$this->output[ $key ]['element'] = array_unique( $this->output[ $key ]['element'] );
541
-				sort( $this->output[ $key ]['element'] );
542
-
543
-				// Trim each element in the array.
544
-				foreach ( $this->output[ $key ]['element'] as $index => $element ) {
545
-					$this->output[ $key ]['element'][ $index ] = trim( $element );
546
-				}
547
-				$this->output[ $key ]['element'] = implode( ',', $this->output[ $key ]['element'] );
548
-			}
549
-
550
-			// Fix for https://github.com/aristath/kirki/issues/1659#issuecomment-346229751.
551
-			$this->output[ $key ]['element'] = str_replace( [ "\t", "\n", "\r", "\0", "\x0B" ], ' ', $this->output[ $key ]['element'] );
552
-			$this->output[ $key ]['element'] = trim( preg_replace( '/\s+/', ' ', $this->output[ $key ]['element'] ) );
553
-		}
554
-	}
555
-
556
-	/**
557
-	 * Sets the $js_vars
558
-	 *
559
-	 * @access protected
560
-	 */
561
-	protected function set_js_vars() {
562
-		if ( ! is_array( $this->js_vars ) ) {
563
-			$this->js_vars = [];
564
-		}
565
-
566
-		// Check if transport is set to auto.
567
-		// If not, then skip the auto-calculations and exit early.
568
-		if ( 'auto' !== $this->transport ) {
569
-			return;
570
-		}
571
-
572
-		// Set transport to refresh initially.
573
-		// Serves as a fallback in case we failt to auto-calculate js_vars.
574
-		$this->transport = 'refresh';
575
-
576
-		$js_vars = [];
577
-
578
-		// Try to auto-generate js_vars.
579
-		// First we need to check if js_vars are empty, and that output is not empty.
580
-		if ( empty( $this->js_vars ) && ! empty( $this->output ) ) {
581
-
582
-			// Start going through each item in the $output array.
583
-			foreach ( $this->output as $output ) {
584
-				$output['function'] = ( isset( $output['function'] ) ) ? $output['function'] : 'style';
585
-
586
-				// If 'element' is not defined, skip this.
587
-				if ( ! isset( $output['element'] ) ) {
588
-					continue;
589
-				}
590
-				if ( is_array( $output['element'] ) ) {
591
-					$output['element'] = implode( ',', $output['element'] );
592
-				}
593
-
594
-				// If there's a sanitize_callback defined skip this, unless we also have a js_callback defined.
595
-				if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) && ! isset( $output['js_callback'] ) ) {
596
-					continue;
597
-				}
598
-
599
-				// If we got this far, it's safe to add this.
600
-				$js_vars[] = $output;
601
-			}
602
-
603
-			// Did we manage to get all the items from 'output'?
604
-			// If not, then we're missing something so don't add this.
605
-			if ( count( $js_vars ) !== count( $this->output ) ) {
606
-				return;
607
-			}
608
-			$this->js_vars   = $js_vars;
609
-			$this->transport = 'postMessage';
610
-		}
611
-	}
612
-
613
-	/**
614
-	 * Sets the $variables
615
-	 *
616
-	 * @access protected
617
-	 */
618
-	protected function set_variables() {
619
-		if ( ! is_array( $this->variables ) ) {
620
-			$variable        = ( is_string( $this->variables ) && ! empty( $this->variables ) ) ? $this->variables : false;
621
-			$this->variables = [];
622
-			if ( $variable && empty( $this->variables ) ) {
623
-				$this->variables[0]['name'] = $variable;
624
-			}
625
-		}
626
-	}
627
-
628
-	/**
629
-	 * Sets the $transport
630
-	 *
631
-	 * @access protected
632
-	 */
633
-	protected function set_transport() {
634
-		if ( 'postmessage' === trim( strtolower( $this->transport ) ) ) {
635
-			$this->transport = 'postMessage';
636
-		}
637
-	}
638
-
639
-	/**
640
-	 * Sets the $required
641
-	 *
642
-	 * @access protected
643
-	 */
644
-	protected function set_required() {
645
-		if ( ! is_array( $this->required ) ) {
646
-			$this->required = [];
647
-		}
648
-	}
649
-
650
-	/**
651
-	 * Sets the $priority
652
-	 *
653
-	 * @access protected
654
-	 */
655
-	protected function set_priority() {
656
-		$this->priority = absint( $this->priority );
657
-	}
658
-
659
-	/**
660
-	 * Sets the $css_vars
661
-	 *
662
-	 * @access protected
663
-	 */
664
-	protected function set_css_vars() {
665
-		if ( is_string( $this->css_vars ) ) {
666
-			$this->css_vars = [ $this->css_vars ];
667
-		}
668
-		if ( isset( $this->css_vars[0] ) && is_string( $this->css_vars[0] ) ) {
669
-			$this->css_vars = [ $this->css_vars ];
670
-		}
671
-		foreach ( $this->css_vars as $key => $val ) {
672
-			if ( ! isset( $val[1] ) ) {
673
-				$this->css_vars[ $key ][1] = '$';
674
-			}
675
-		}
676
-	}
23
+    /**
24
+     * An array of the field arguments.
25
+     *
26
+     * @access protected
27
+     * @var array
28
+     */
29
+    protected $args = [];
30
+
31
+    /**
32
+     * The ID of the kirki_config we're using.
33
+     *
34
+     * @see Kirki\Compatibility\Config
35
+     * @access protected
36
+     * @var string
37
+     */
38
+    protected $kirki_config = 'global';
39
+
40
+    /**
41
+     * The capability required so that users can edit this field.
42
+     *
43
+     * @access protected
44
+     * @var string
45
+     */
46
+    protected $capability = 'edit_theme_options';
47
+
48
+    /**
49
+     * If we're using options instead of theme_mods
50
+     * and we want them serialized, this is the option that
51
+     * will saved in the db.
52
+     *
53
+     * @access protected
54
+     * @var string
55
+     */
56
+    protected $option_name = '';
57
+
58
+    /**
59
+     * Custom input attributes (defined as an array).
60
+     *
61
+     * @access protected
62
+     * @var array
63
+     */
64
+    protected $input_attrs = [];
65
+
66
+    /**
67
+     * Preset choices.
68
+     *
69
+     * @access protected
70
+     * @var array
71
+     */
72
+    protected $preset = [];
73
+
74
+    /**
75
+     * CSS Variables.
76
+     *
77
+     * @access protected
78
+     * @var array
79
+     */
80
+    protected $css_vars = [];
81
+
82
+    /**
83
+     * Use "theme_mod" or "option".
84
+     *
85
+     * @access protected
86
+     * @var string
87
+     */
88
+    protected $option_type = 'theme_mod';
89
+
90
+    /**
91
+     * The name of this setting (id for the db).
92
+     *
93
+     * @access protected
94
+     * @var string|array
95
+     */
96
+    protected $settings = '';
97
+
98
+    /**
99
+     * Set to true if you want to disable all CSS output for this field.
100
+     *
101
+     * @access protected
102
+     * @var bool
103
+     */
104
+    protected $disable_output = false;
105
+
106
+    /**
107
+     * The field type.
108
+     *
109
+     * @access protected
110
+     * @var string
111
+     */
112
+    protected $type = 'kirki-generic';
113
+
114
+    /**
115
+     * Some fields require options to be set.
116
+     * We're whitelisting the property here
117
+     * and suggest you validate this in a child class.
118
+     *
119
+     * @access protected
120
+     * @var array
121
+     */
122
+    protected $choices = [];
123
+
124
+    /**
125
+     * Assign this field to a section.
126
+     * Fields not assigned to a section will not be displayed in the customizer.
127
+     *
128
+     * @access protected
129
+     * @var string
130
+     */
131
+    protected $section = '';
132
+
133
+    /**
134
+     * The default value for this field.
135
+     *
136
+     * @access protected
137
+     * @var string|array|bool
138
+     */
139
+    protected $default = '';
140
+
141
+    /**
142
+     * Priority determines the position of a control inside a section.
143
+     * Lower priority numbers move the control to the top.
144
+     *
145
+     * @access protected
146
+     * @var int
147
+     */
148
+    protected $priority = 10;
149
+
150
+    /**
151
+     * Unique ID for this field.
152
+     * This is auto-calculated from the $settings argument.
153
+     *
154
+     * @access protected
155
+     * @var string
156
+     */
157
+    protected $id = '';
158
+
159
+    /**
160
+     * Use if you want to automatically generate CSS from this field's value.
161
+     *
162
+     * @see https://kirki.org/docs/arguments/output
163
+     * @access protected
164
+     * @var array
165
+     */
166
+    protected $output = [];
167
+
168
+    /**
169
+     * Use to automatically generate postMessage scripts.
170
+     * Not necessary to use if you use 'transport' => 'auto'
171
+     * and have already set an array for the 'output' argument.
172
+     *
173
+     * @see https://kirki.org/docs/arguments/js_vars
174
+     * @access protected
175
+     * @var array
176
+     */
177
+    protected $js_vars = [];
178
+
179
+    /**
180
+     * If you want to use a CSS compiler, then use this to set the variable names.
181
+     *
182
+     * @see https://kirki.org/docs/arguments/variables
183
+     * @access protected
184
+     * @var array
185
+     */
186
+    protected $variables = [];
187
+
188
+    /**
189
+     * Text that will be used in a tooltip to provide extra info for this field.
190
+     *
191
+     * @access protected
192
+     * @var string
193
+     */
194
+    protected $tooltip = '';
195
+
196
+    /**
197
+     * A custom callback to determine if the field should be visible or not.
198
+     *
199
+     * @access protected
200
+     * @var string|array
201
+     */
202
+    protected $active_callback = '__return_true';
203
+
204
+    /**
205
+     * A custom sanitize callback that will be used to properly save the values.
206
+     *
207
+     * @access protected
208
+     * @var string|array
209
+     */
210
+    protected $sanitize_callback = '';
211
+
212
+    /**
213
+     * Use 'refresh', 'postMessage' or 'auto'.
214
+     * 'auto' will automatically geberate any 'js_vars' from the 'output' argument.
215
+     *
216
+     * @access protected
217
+     * @var string
218
+     */
219
+    protected $transport = 'refresh';
220
+
221
+    /**
222
+     * Define dependencies to show/hide this field based on the values of other fields.
223
+     *
224
+     * @access protected
225
+     * @var array
226
+     */
227
+    protected $required = [];
228
+
229
+    /**
230
+     * Partial Refreshes array.
231
+     *
232
+     * @access protected
233
+     * @var array
234
+     */
235
+    protected $partial_refresh = [];
236
+
237
+    /**
238
+     * The class constructor.
239
+     * Parses and sanitizes all field arguments.
240
+     * Then it adds the field to Kirki::$fields.
241
+     *
242
+     * @access public
243
+     * @param string $config_id    The ID of the config we want to use.
244
+     *                             Defaults to "global".
245
+     *                             Configs are handled by the Kirki\Compatibility\Config class.
246
+     * @param array  $args         The arguments of the field.
247
+     */
248
+    public function __construct( $config_id = 'global', $args = [] ) {
249
+
250
+        /**
251
+         * In case the user only provides 1 argument,
252
+         * assume that the provided argument is $args and set $config_id = 'global'.
253
+         */
254
+        if ( is_array( $config_id ) && empty( $args ) ) {
255
+            $args      = $config_id;
256
+            $config_id = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
257
+        }
258
+
259
+        if ( isset( $args['setting'] ) && ! empty( $args['setting'] ) && ( ! isset( $args['settings'] ) || empty( $args['settings'] ) ) ) {
260
+            /* translators: %s represents the field ID where the error occurs. */
261
+            _doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Typo found in field %s - setting instead of settings.', 'kirki' ), esc_html( $args['settings'] ) ), '3.0.10' );
262
+            $args['settings'] = $args['setting'];
263
+            unset( $args['setting'] );
264
+        }
265
+
266
+        $args['kirki_config'] = $config_id;
267
+
268
+        $this->kirki_config = $config_id;
269
+
270
+        if ( '' === $config_id ) {
271
+            /* translators: %1$s represents the field ID where the error occurs. %2$s is the URL in the documentation site. */
272
+            _doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Config not defined for field %1$s - See %2$s for details on how to properly add fields.', 'kirki' ), esc_html( $args['settings'] ), 'https://aristath.github.io/kirki/docs/getting-started/fields.html' ), '3.0.10' );
273
+            $this->kirki_config = 'global';
274
+        }
275
+
276
+        // Get defaults from the class.
277
+        $defaults = get_class_vars( __CLASS__ );
278
+
279
+        // Get the config arguments, and merge them with the defaults.
280
+        $config_defaults = ( isset( Kirki::$config['global'] ) ) ? Kirki::$config['global'] : [];
281
+
282
+        if ( 'global' !== $this->kirki_config && isset( Kirki::$config[ $this->kirki_config ] ) ) {
283
+            $config_defaults = Kirki::$config[ $this->kirki_config ];
284
+        }
285
+
286
+        $config_defaults = ( is_array( $config_defaults ) ) ? $config_defaults : [];
287
+
288
+        foreach ( $config_defaults as $key => $value ) {
289
+            if ( isset( $defaults[ $key ] ) && ! empty( $value ) && $value !== $defaults[ $key ] ) {
290
+                $defaults[ $key ] = $value;
291
+            }
292
+        }
293
+
294
+        // Merge our args with the defaults.
295
+        $args = wp_parse_args( $args, $defaults );
296
+
297
+        // Set the class properties using the parsed args.
298
+        foreach ( $args as $key => $value ) {
299
+            $this->$key = $value;
300
+        }
301
+
302
+        $this->args = $args;
303
+
304
+        $this->set_field();
305
+
306
+        // Instantiate the \Kirki\Field to apply hooks.
307
+        new \Kirki\Field\None( $this->args );
308
+
309
+    }
310
+
311
+    /**
312
+     * Processes the field arguments
313
+     *
314
+     * @access protected
315
+     */
316
+    protected function set_field() {
317
+
318
+        $properties = get_class_vars( __CLASS__ );
319
+
320
+        // Some things must run before the others.
321
+        $this->set_option_type();
322
+        $this->set_settings();
323
+
324
+        // Sanitize the properties, skipping the ones that have already run above.
325
+        foreach ( array_keys( $properties ) as $property ) {
326
+            if ( in_array( $property, [ 'option_name', 'option_type', 'settings' ], true ) ) {
327
+                continue;
328
+            }
329
+            if ( method_exists( $this, 'set_' . $property ) ) {
330
+                $method_name = 'set_' . $property;
331
+                $this->$method_name();
332
+            }
333
+        }
334
+
335
+        // Get all arguments with their values.
336
+        $args = get_object_vars( $this );
337
+
338
+        foreach ( array_keys( $args ) as $key ) {
339
+            $args[ $key ] = $this->$key;
340
+        }
341
+
342
+        // Add the field to the static $fields variable properly indexed.
343
+        Kirki::$fields[ $this->settings ] = $args;
344
+
345
+    }
346
+
347
+    /**
348
+     * Escape the $section.
349
+     *
350
+     * @access protected
351
+     */
352
+    protected function set_input_attrs() {
353
+        $this->input_attrs = (array) $this->input_attrs;
354
+    }
355
+
356
+    /**
357
+     * Make sure we're using the correct option_type
358
+     *
359
+     * @access protected
360
+     */
361
+    protected function set_option_type() {
362
+
363
+        // Take care of common typos.
364
+        if ( 'options' === $this->option_type ) {
365
+            $this->option_type = 'option';
366
+        }
367
+
368
+        // Take care of common typos.
369
+        if ( 'theme_mods' === $this->option_type ) {
370
+            /* translators: %1$s represents the field ID where the error occurs. */
371
+            _doing_it_wrong( __METHOD__, sprintf( esc_html( 'Typo found in field %s - "theme_mods" vs "theme_mod"', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
372
+            $this->option_type = 'theme_mod';
373
+        }
374
+    }
375
+
376
+    /**
377
+     * Modifications for partial refreshes.
378
+     *
379
+     * @access protected
380
+     */
381
+    protected function set_partial_refresh() {
382
+        if ( ! is_array( $this->partial_refresh ) ) {
383
+            $this->partial_refresh = [];
384
+        }
385
+        foreach ( $this->partial_refresh as $id => $args ) {
386
+            if ( ! is_array( $args ) || ! isset( $args['selector'] ) || ! isset( $args['render_callback'] ) || ! is_callable( $args['render_callback'] ) ) {
387
+                /* translators: %1$s represents the field ID where the error occurs. */
388
+                _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"partial_refresh" invalid entry in field %s', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
389
+                unset( $this->partial_refresh[ $id ] );
390
+                continue;
391
+            }
392
+        }
393
+        if ( ! empty( $this->partial_refresh ) ) {
394
+            $this->transport = 'postMessage';
395
+        }
396
+    }
397
+
398
+    /**
399
+     * Sets the settings.
400
+     * If we're using serialized options it makes sure that settings are properly formatted.
401
+     * We'll also be escaping all setting names here for consistency.
402
+     *
403
+     * @access protected
404
+     */
405
+    protected function set_settings() {
406
+
407
+        // If settings is not an array, temporarily convert it to an array.
408
+        // This is just to allow us to process everything the same way and avoid code duplication.
409
+        // if settings is not an array then it will not be set as an array in the end.
410
+        if ( ! is_array( $this->settings ) ) {
411
+            $this->settings = [
412
+                'kirki_placeholder_setting' => $this->settings,
413
+            ];
414
+        }
415
+        $settings = [];
416
+        foreach ( $this->settings as $setting_key => $setting_value ) {
417
+            $settings[ $setting_key ] = $setting_value;
418
+
419
+            // If we're using serialized options then we need to spice this up.
420
+            if ( 'option' === $this->option_type && '' !== $this->option_name && ( false === strpos( $setting_key, '[' ) ) ) {
421
+                $settings[ $setting_key ] = "{$this->option_name}[{$setting_value}]";
422
+            }
423
+        }
424
+        $this->settings = $settings;
425
+        if ( isset( $this->settings['kirki_placeholder_setting'] ) ) {
426
+            $this->settings = $this->settings['kirki_placeholder_setting'];
427
+        }
428
+    }
429
+
430
+    /**
431
+     * Sets the active_callback
432
+     * If we're using the $required argument,
433
+     * Then this is where the switch is made to our evaluation method.
434
+     *
435
+     * @access protected
436
+     */
437
+    protected function set_active_callback() {
438
+
439
+        if ( is_array( $this->active_callback ) ) {
440
+
441
+            if ( ! is_callable( $this->active_callback ) ) {
442
+
443
+                // Bugfix for https://github.com/aristath/kirki/issues/1961.
444
+                foreach ( $this->active_callback as $key => $val ) {
445
+                    if ( is_callable( $val ) ) {
446
+                        unset( $this->active_callback[ $key ] );
447
+                    }
448
+                }
449
+                if ( isset( $this->active_callback[0] ) ) {
450
+                    $this->required = $this->active_callback;
451
+                }
452
+            }
453
+        }
454
+
455
+        if ( ! empty( $this->required ) ) {
456
+            $this->active_callback = '__return_true';
457
+            return;
458
+        }
459
+        // No need to proceed any further if we're using the default value.
460
+        if ( '__return_true' === $this->active_callback ) {
461
+            return;
462
+        }
463
+
464
+        // Make sure the function is callable, otherwise fallback to __return_true.
465
+        if ( ! is_callable( $this->active_callback ) ) {
466
+            $this->active_callback = '__return_true';
467
+        }
468
+
469
+    }
470
+
471
+    /**
472
+     * Sets the $id.
473
+     * Setting the ID should happen after the 'settings' sanitization.
474
+     * This way we can also properly handle cases where the option_type is set to 'option'
475
+     * and we're using an array instead of individual options.
476
+     *
477
+     * @access protected
478
+     */
479
+    protected function set_id() {
480
+        $this->id = sanitize_key( str_replace( '[', '-', str_replace( ']', '', $this->settings ) ) );
481
+    }
482
+
483
+    /**
484
+     * Sets the $choices.
485
+     *
486
+     * @access protected
487
+     */
488
+    protected function set_choices() {
489
+        if ( ! is_array( $this->choices ) ) {
490
+            $this->choices = [];
491
+        }
492
+    }
493
+
494
+    /**
495
+     * Escapes the $disable_output.
496
+     *
497
+     * @access protected
498
+     */
499
+    protected function set_disable_output() {
500
+        $this->disable_output = (bool) $this->disable_output;
501
+    }
502
+
503
+    /**
504
+     * Sets the $sanitize_callback
505
+     *
506
+     * @access protected
507
+     */
508
+    protected function set_output() {
509
+        if ( empty( $this->output ) ) {
510
+            return;
511
+        }
512
+        if ( ! is_array( $this->output ) ) {
513
+            /* translators: The field ID where the error occurs. */
514
+            _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
515
+            $this->output = [
516
+                [
517
+                    'element' => $this->output,
518
+                ],
519
+            ];
520
+        }
521
+
522
+        // Convert to array of arrays if needed.
523
+        if ( isset( $this->output['element'] ) ) {
524
+            /* translators: The field ID where the error occurs. */
525
+            _doing_it_wrong( __METHOD__, sprintf( esc_html__( '"output" invalid format in field %s. The "output" argument should be defined as an array of arrays.', 'kirki' ), esc_html( $this->settings ) ), '3.0.10' );
526
+            $this->output = [ $this->output ];
527
+        }
528
+
529
+        foreach ( $this->output as $key => $output ) {
530
+            if ( empty( $output ) || ! isset( $output['element'] ) ) {
531
+                unset( $this->output[ $key ] );
532
+                continue;
533
+            }
534
+            if ( ! isset( $output['sanitize_callback'] ) && isset( $output['callback'] ) ) {
535
+                $this->output[ $key ]['sanitize_callback'] = $output['callback'];
536
+            }
537
+
538
+            // Convert element arrays to strings.
539
+            if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
540
+                $this->output[ $key ]['element'] = array_unique( $this->output[ $key ]['element'] );
541
+                sort( $this->output[ $key ]['element'] );
542
+
543
+                // Trim each element in the array.
544
+                foreach ( $this->output[ $key ]['element'] as $index => $element ) {
545
+                    $this->output[ $key ]['element'][ $index ] = trim( $element );
546
+                }
547
+                $this->output[ $key ]['element'] = implode( ',', $this->output[ $key ]['element'] );
548
+            }
549
+
550
+            // Fix for https://github.com/aristath/kirki/issues/1659#issuecomment-346229751.
551
+            $this->output[ $key ]['element'] = str_replace( [ "\t", "\n", "\r", "\0", "\x0B" ], ' ', $this->output[ $key ]['element'] );
552
+            $this->output[ $key ]['element'] = trim( preg_replace( '/\s+/', ' ', $this->output[ $key ]['element'] ) );
553
+        }
554
+    }
555
+
556
+    /**
557
+     * Sets the $js_vars
558
+     *
559
+     * @access protected
560
+     */
561
+    protected function set_js_vars() {
562
+        if ( ! is_array( $this->js_vars ) ) {
563
+            $this->js_vars = [];
564
+        }
565
+
566
+        // Check if transport is set to auto.
567
+        // If not, then skip the auto-calculations and exit early.
568
+        if ( 'auto' !== $this->transport ) {
569
+            return;
570
+        }
571
+
572
+        // Set transport to refresh initially.
573
+        // Serves as a fallback in case we failt to auto-calculate js_vars.
574
+        $this->transport = 'refresh';
575
+
576
+        $js_vars = [];
577
+
578
+        // Try to auto-generate js_vars.
579
+        // First we need to check if js_vars are empty, and that output is not empty.
580
+        if ( empty( $this->js_vars ) && ! empty( $this->output ) ) {
581
+
582
+            // Start going through each item in the $output array.
583
+            foreach ( $this->output as $output ) {
584
+                $output['function'] = ( isset( $output['function'] ) ) ? $output['function'] : 'style';
585
+
586
+                // If 'element' is not defined, skip this.
587
+                if ( ! isset( $output['element'] ) ) {
588
+                    continue;
589
+                }
590
+                if ( is_array( $output['element'] ) ) {
591
+                    $output['element'] = implode( ',', $output['element'] );
592
+                }
593
+
594
+                // If there's a sanitize_callback defined skip this, unless we also have a js_callback defined.
595
+                if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) && ! isset( $output['js_callback'] ) ) {
596
+                    continue;
597
+                }
598
+
599
+                // If we got this far, it's safe to add this.
600
+                $js_vars[] = $output;
601
+            }
602
+
603
+            // Did we manage to get all the items from 'output'?
604
+            // If not, then we're missing something so don't add this.
605
+            if ( count( $js_vars ) !== count( $this->output ) ) {
606
+                return;
607
+            }
608
+            $this->js_vars   = $js_vars;
609
+            $this->transport = 'postMessage';
610
+        }
611
+    }
612
+
613
+    /**
614
+     * Sets the $variables
615
+     *
616
+     * @access protected
617
+     */
618
+    protected function set_variables() {
619
+        if ( ! is_array( $this->variables ) ) {
620
+            $variable        = ( is_string( $this->variables ) && ! empty( $this->variables ) ) ? $this->variables : false;
621
+            $this->variables = [];
622
+            if ( $variable && empty( $this->variables ) ) {
623
+                $this->variables[0]['name'] = $variable;
624
+            }
625
+        }
626
+    }
627
+
628
+    /**
629
+     * Sets the $transport
630
+     *
631
+     * @access protected
632
+     */
633
+    protected function set_transport() {
634
+        if ( 'postmessage' === trim( strtolower( $this->transport ) ) ) {
635
+            $this->transport = 'postMessage';
636
+        }
637
+    }
638
+
639
+    /**
640
+     * Sets the $required
641
+     *
642
+     * @access protected
643
+     */
644
+    protected function set_required() {
645
+        if ( ! is_array( $this->required ) ) {
646
+            $this->required = [];
647
+        }
648
+    }
649
+
650
+    /**
651
+     * Sets the $priority
652
+     *
653
+     * @access protected
654
+     */
655
+    protected function set_priority() {
656
+        $this->priority = absint( $this->priority );
657
+    }
658
+
659
+    /**
660
+     * Sets the $css_vars
661
+     *
662
+     * @access protected
663
+     */
664
+    protected function set_css_vars() {
665
+        if ( is_string( $this->css_vars ) ) {
666
+            $this->css_vars = [ $this->css_vars ];
667
+        }
668
+        if ( isset( $this->css_vars[0] ) && is_string( $this->css_vars[0] ) ) {
669
+            $this->css_vars = [ $this->css_vars ];
670
+        }
671
+        foreach ( $this->css_vars as $key => $val ) {
672
+            if ( ! isset( $val[1] ) ) {
673
+                $this->css_vars[ $key ][1] = '$';
674
+            }
675
+        }
676
+    }
677 677
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/compatibility/src/Control.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -16,114 +16,114 @@
 block discarded – undo
16 16
  */
17 17
 class Control {
18 18
 
19
-	/**
20
-	 * The $wp_customize WordPress global.
21
-	 *
22
-	 * @access protected
23
-	 * @var WP_Customize_Manager
24
-	 */
25
-	protected $wp_customize;
26
-
27
-	/**
28
-	 * An array of all available control types.
29
-	 *
30
-	 * @access protected
31
-	 * @var array
32
-	 */
33
-	protected static $control_types = [];
34
-
35
-	/**
36
-	 * The class constructor.
37
-	 * Creates the actual controls in the customizer.
38
-	 *
39
-	 * @access public
40
-	 * @param array $args The field definition as sanitized in Kirki\Field.
41
-	 */
42
-	public function __construct( $args ) {
43
-
44
-		// Set the $wp_customize property.
45
-		global $wp_customize;
46
-		if ( ! $wp_customize ) {
47
-			return;
48
-		}
49
-		$this->wp_customize = $wp_customize;
50
-
51
-		// Set the control types.
52
-		$this->set_control_types();
53
-
54
-		// Add the control.
55
-		$this->add_control( $args );
56
-
57
-	}
58
-
59
-	/**
60
-	 * Get the class name of the class needed to create tis control.
61
-	 *
62
-	 * @access private
63
-	 * @param array $args The field definition as sanitized in Kirki\Field.
64
-	 *
65
-	 * @return         string   the name of the class that will be used to create this control.
66
-	 */
67
-	final function get_control_class_name( $args ) {
68
-
69
-		// Set a default class name.
70
-		$class_name = 'WP_Customize_Control';
71
-
72
-		// Get the classname from the array of control classnames.
73
-		if ( array_key_exists( $args['type'], self::$control_types ) ) {
74
-			$class_name = self::$control_types[ $args['type'] ];
75
-		}
76
-		return $class_name;
77
-	}
78
-
79
-	/**
80
-	 * Adds the control.
81
-	 *
82
-	 * @access protected
83
-	 * @param array $args The field definition as sanitized in Kirki\Field.
84
-	 */
85
-	final protected function add_control( $args ) {
86
-
87
-		// Get the name of the class we're going to use.
88
-		$class_name = $this->get_control_class_name( $args );
89
-
90
-		/**
91
-		 * Allow filtering the arguments.
92
-		 *
93
-		 * @since 0.1
94
-		 * @param array                $args   The arguments.
95
-		 * @param WP_Customize_Manager $wp_customize The customizer instance.
96
-		 * @return array                             Return the arguments.
97
-		 */
98
-		$args = apply_filters( 'kirki_field_add_control_args', $args, $this->wp_customize );
99
-
100
-		// Add the control.
101
-		$this->wp_customize->add_control( new $class_name( $this->wp_customize, $args['settings'], $args ) );
102
-
103
-	}
104
-
105
-	/**
106
-	 * Sets the $control_types property.
107
-	 * Makes sure the kirki_control_types filter is applied
108
-	 * and that the defined classes actually exist.
109
-	 * If a defined class does not exist, it is removed.
110
-	 *
111
-	 * @access private
112
-	 */
113
-	final function set_control_types() {
114
-
115
-		// Early exit if this has already run.
116
-		if ( ! empty( self::$control_types ) ) {
117
-			return;
118
-		}
119
-
120
-		self::$control_types = apply_filters( 'kirki_control_types', [] );
121
-
122
-		// Make sure the defined classes actually exist.
123
-		foreach ( self::$control_types as $key => $classname ) {
124
-			if ( ! class_exists( $classname ) ) {
125
-				unset( self::$control_types[ $key ] );
126
-			}
127
-		}
128
-	}
19
+    /**
20
+     * The $wp_customize WordPress global.
21
+     *
22
+     * @access protected
23
+     * @var WP_Customize_Manager
24
+     */
25
+    protected $wp_customize;
26
+
27
+    /**
28
+     * An array of all available control types.
29
+     *
30
+     * @access protected
31
+     * @var array
32
+     */
33
+    protected static $control_types = [];
34
+
35
+    /**
36
+     * The class constructor.
37
+     * Creates the actual controls in the customizer.
38
+     *
39
+     * @access public
40
+     * @param array $args The field definition as sanitized in Kirki\Field.
41
+     */
42
+    public function __construct( $args ) {
43
+
44
+        // Set the $wp_customize property.
45
+        global $wp_customize;
46
+        if ( ! $wp_customize ) {
47
+            return;
48
+        }
49
+        $this->wp_customize = $wp_customize;
50
+
51
+        // Set the control types.
52
+        $this->set_control_types();
53
+
54
+        // Add the control.
55
+        $this->add_control( $args );
56
+
57
+    }
58
+
59
+    /**
60
+     * Get the class name of the class needed to create tis control.
61
+     *
62
+     * @access private
63
+     * @param array $args The field definition as sanitized in Kirki\Field.
64
+     *
65
+     * @return         string   the name of the class that will be used to create this control.
66
+     */
67
+    final function get_control_class_name( $args ) {
68
+
69
+        // Set a default class name.
70
+        $class_name = 'WP_Customize_Control';
71
+
72
+        // Get the classname from the array of control classnames.
73
+        if ( array_key_exists( $args['type'], self::$control_types ) ) {
74
+            $class_name = self::$control_types[ $args['type'] ];
75
+        }
76
+        return $class_name;
77
+    }
78
+
79
+    /**
80
+     * Adds the control.
81
+     *
82
+     * @access protected
83
+     * @param array $args The field definition as sanitized in Kirki\Field.
84
+     */
85
+    final protected function add_control( $args ) {
86
+
87
+        // Get the name of the class we're going to use.
88
+        $class_name = $this->get_control_class_name( $args );
89
+
90
+        /**
91
+         * Allow filtering the arguments.
92
+         *
93
+         * @since 0.1
94
+         * @param array                $args   The arguments.
95
+         * @param WP_Customize_Manager $wp_customize The customizer instance.
96
+         * @return array                             Return the arguments.
97
+         */
98
+        $args = apply_filters( 'kirki_field_add_control_args', $args, $this->wp_customize );
99
+
100
+        // Add the control.
101
+        $this->wp_customize->add_control( new $class_name( $this->wp_customize, $args['settings'], $args ) );
102
+
103
+    }
104
+
105
+    /**
106
+     * Sets the $control_types property.
107
+     * Makes sure the kirki_control_types filter is applied
108
+     * and that the defined classes actually exist.
109
+     * If a defined class does not exist, it is removed.
110
+     *
111
+     * @access private
112
+     */
113
+    final function set_control_types() {
114
+
115
+        // Early exit if this has already run.
116
+        if ( ! empty( self::$control_types ) ) {
117
+            return;
118
+        }
119
+
120
+        self::$control_types = apply_filters( 'kirki_control_types', [] );
121
+
122
+        // Make sure the defined classes actually exist.
123
+        foreach ( self::$control_types as $key => $classname ) {
124
+            if ( ! class_exists( $classname ) ) {
125
+                unset( self::$control_types[ $key ] );
126
+            }
127
+        }
128
+    }
129 129
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/compatibility/src/Aliases.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -19,166 +19,166 @@
 block discarded – undo
19 19
  */
20 20
 class Aliases {
21 21
 
22
-	/**
23
-	 * An array of class aliases.
24
-	 *
25
-	 * @access private
26
-	 * @since 0.1
27
-	 * @var array
28
-	 */
29
-	private $aliases = [
30
-		'generic'    => [
31
-			[ 'Kirki\Compatibility\Kirki', 'Kirki' ],
32
-			[ 'Kirki\Compatibility\Config', 'Kirki_Config' ],
33
-			[ 'Kirki\Compatibility\Control', 'Kirki_Control' ],
34
-			[ 'Kirki\Compatibility\Field', 'Kirki_Field' ],
35
-			[ 'Kirki\Util\Helper', 'Kirki_Helper' ],
36
-			[ 'Kirki\Compatibility\Init', 'Kirki_Init' ],
37
-			[ 'Kirki\L10n', 'Kirki_L10n' ],
38
-			[ 'Kirki\Compatibility\Modules', 'Kirki_Modules' ],
39
-			[ 'Kirki\Compatibility\Sanitize_Values', 'Kirki_Sanitize_Values' ],
40
-			[ 'Kirki\Compatibility\Section', 'Kirki_Section' ],
41
-			[ 'Kirki\Compatibility\Values', 'Kirki_Values' ],
42
-			[ 'Kirki\Util\Util', 'Kirki_Util' ],
43
-			[ 'Kirki\Compatibility\Framework', 'Kirki_Toolkit' ],
44
-			[ 'Kirki\Module\CSS', 'Kirki_Modules_CSS' ],
45
-			[ 'Kirki\Module\CSS\Output', 'Kirki_Output' ],
46
-			[ 'Kirki\Module\CSS\Generator', 'Kirki_Modules_CSS_Generator' ],
47
-			[ 'Kirki\Module\CSS\Property', 'Kirki_Output_Property' ],
48
-			[ 'Kirki\Module\CSS\Property\Font_Family', 'Kirki_Output_Property_Font_Family' ],
49
-			[ 'Kirki\Module\Preset', 'Kirki_Modules_Preset' ],
50
-			[ 'Kirki\Module\Tooltips', 'Kirki_Modules_Tooltips' ],
51
-			[ 'Kirki\Module\Webfonts', 'Kirki_Modules_Webfonts' ],
52
-			[ 'Kirki\Module\Webfonts\Google', 'Kirki_Fonts_Google' ],
53
-			[ 'Kirki\Module\Webfonts\Fonts', 'Kirki_Fonts' ],
54
-			[ 'Kirki\Module\Webfonts\Embed', 'Kirki_Modules_Webfonts_Embed' ],
55
-			[ 'Kirki\Module\Webfonts\Async', 'Kirki_Modules_Webfonts_Async' ],
56
-			[ 'Kirki\Module\Field_Dependencies', 'Kirki_Modules_Field_Dependencies' ],
57
-			[ 'Kirki\Module\Editor_Styles', 'Kirki_Modules_Gutenberg' ],
58
-			[ 'Kirki\Module\Selective_Refresh', 'Kirki_Modules_Selective_Refresh' ],
59
-			[ 'Kirki\Module\Postmessage', 'Kirki_Modules_Postmessage' ],
60
-			[ 'Kirki\Field\Background', 'Kirki_Field_Background' ],
61
-			[ 'Kirki\Field\CSS\Background', 'Kirki_Output_Field_Background' ],
62
-			[ 'Kirki\Field\Checkbox', 'Kirki_Field_Checkbox' ],
63
-			[ 'Kirki\Field\Checkbox_Switch', 'Kirki_Field_Switch' ],
64
-			[ 'Kirki\Field\Checkbox_Switch', 'Kirki\Field\Switch' ], // Preventing typo.
65
-			[ 'Kirki\Field\Checkbox_Toggle', 'Kirki_Field_Toggle' ],
66
-			[ 'Kirki\Field\Checkbox_Toggle', 'Kirki\Field\Toggle' ], // Preventing typo.
67
-			[ 'Kirki\Field\Code', 'Kirki_Field_Code' ],
68
-			[ 'Kirki\Field\Color', 'Kirki_Field_Color' ],
69
-			[ 'Kirki\Field\Color', 'Kirki_Field_Color_Alpha' ],
70
-			[ 'Kirki\Field\Color_Palette', 'Kirki_Field_Color_Palette' ],
71
-			[ 'Kirki\Field\Custom', 'Kirki_Field_Custom' ],
72
-			[ 'Kirki\Field\Dashicons', 'Kirki_Field_Dashicons' ],
73
-			[ 'Kirki\Field\Date', 'Kirki_Field_Date' ],
74
-			[ 'Kirki\Field\Dimension', 'Kirki_Field_Dimension' ],
75
-			[ 'Kirki\Field\Dimensions', 'Kirki_Field_Dimensions' ],
76
-			[ 'Kirki\Field\CSS\Dimensions', 'Kirki_Output_Field_Dimensions' ],
77
-			[ 'Kirki\Field\Dimensions', 'Kirki_Field_Spacing' ],
78
-			[ 'Kirki\Field\Dimensions', 'Kirki\Field\Spacing' ],
79
-			[ 'Kirki\Field\Editor', 'Kirki_Field_Editor' ],
80
-			[ 'Kirki\Field\FontAwesome', 'Kirki_Field_FontAwesome' ],
81
-			[ 'Kirki\Field\Generic', 'Kirki_Field_Kirki_Generic' ],
82
-			[ 'Kirki\Field\Generic', 'Kirki_Field_Generic' ],
83
-			[ 'Kirki\Field\Text', 'Kirki_Field_Text' ],
84
-			[ 'Kirki\Field\Textarea', 'Kirki_Field_Textarea' ],
85
-			[ 'Kirki\Field\URL', 'Kirki_Field_URL' ],
86
-			[ 'Kirki\Field\URL', 'Kirki_Field_Link' ],
87
-			[ 'Kirki\Field\URL', 'Kirki\Field\Link' ],
88
-			[ 'Kirki\Field\Image', 'Kirki_Field_Image' ],
89
-			[ 'Kirki\Field\CSS\Image', 'Kirki_Output_Field_Image' ],
90
-			[ 'Kirki\Field\Multicheck', 'Kirki_Field_Multicheck' ],
91
-			[ 'Kirki\Field\Multicolor', 'Kirki_Field_Multicolor' ],
92
-			[ 'Kirki\Field\CSS\Multicolor', 'Kirki_Output_Field_Multicolor' ],
93
-			[ 'Kirki\Field\Number', 'Kirki_Field_Number' ],
94
-			[ 'Kirki\Field\Palette', 'Kirki_Field_Palette' ],
95
-			[ 'Kirki\Field\Repeater', 'Kirki_Field_Repeater' ],
96
-			[ 'Kirki\Field\Dropdown_Pages', 'Kirki_Field_Dropdown_Pages' ],
97
-			[ 'Kirki\Field\Preset', 'Kirki_Field_Preset' ],
98
-			[ 'Kirki\Field\Select', 'Kirki_Field_Select' ],
99
-			[ 'Kirki\Field\Slider', 'Kirki_Field_Slider' ],
100
-			[ 'Kirki\Field\Sortable', 'Kirki_Field_Sortable' ],
101
-			[ 'Kirki\Field\Typography', 'Kirki_Field_Typography' ],
102
-			[ 'Kirki\Field\CSS\Typography', 'Kirki_Output_Field_Typography' ],
103
-			[ 'Kirki\Field\Upload', 'Kirki_Field_Upload' ],
104
-		],
105
-		'customizer' => [
106
-			[ 'Kirki\Control\Base', 'Kirki_Control_Base' ],
107
-			[ 'Kirki\Control\Base', 'Kirki_Customize_Control' ],
108
-			[ 'Kirki\Control\Checkbox', 'Kirki_Control_Checkbox' ],
109
-			[ 'Kirki\Control\Checkbox_Switch', 'Kirki_Control_Switch' ],
110
-			[ 'Kirki\Control\Checkbox_Toggle', 'Kirki_Control_Toggle' ],
111
-			[ 'WP_Customize_Code_Editor_Control', 'Kirki_Control_Code' ],
112
-			[ 'Kirki\Control\Color', 'Kirki_Control_Color' ],
113
-			[ 'Kirki\Control\Color_Palette', 'Kirki_Control_Color_Palette' ],
114
-			[ 'WP_Customize_Cropped_Image_Control', 'Kirki_Control_Cropped_Image' ],
115
-			[ 'Kirki\Control\Custom', 'Kirki_Control_Custom' ],
116
-			[ 'Kirki\Control\Dashicons', 'Kirki_Control_Dashicons' ],
117
-			[ 'Kirki\Control\Date', 'Kirki_Control_Date' ],
118
-			[ 'Kirki\Control\Dimension', 'Kirki_Control_Dimension' ],
119
-			[ 'Kirki\Control\Editor', 'Kirki_Control_Editor' ],
120
-			[ 'Kirki\Control\Generic', 'Kirki_Control_Generic' ],
121
-			[ 'Kirki\Control\Image', 'Kirki_Control_Image' ],
122
-			[ 'Kirki\Control\Multicheck', 'Kirki_Control_Multicheck' ],
123
-			[ 'Kirki\Control\Generic', 'Kirki_Control_Number' ],
124
-			[ 'Kirki\Control\Palette', 'Kirki_Control_Palette' ],
125
-			[ 'Kirki\Control\Radio', 'Kirki_Control_Radio' ],
126
-			[ 'Kirki\Control\Radio_Buttonset', 'Kirki_Control_Radio_Buttonset' ],
127
-			[ 'Kirki\Control\Radio_Image', 'Kirki_Control_Radio_Image' ],
128
-			[ 'Kirki\Control\Radio_Image', 'Kirki_Controls_Radio_Image_Control' ],
129
-			[ 'Kirki\Control\Repeater', 'Kirki_Control_Repeater' ],
130
-			[ 'Kirki\Control\Select', 'Kirki_Control_Select' ],
131
-			[ 'Kirki\Control\Slider', 'Kirki_Control_Slider' ],
132
-			[ 'Kirki\Control\Sortable', 'Kirki_Control_Sortable' ],
133
-			[ 'Kirki\Control\Upload', 'Kirki_Control_Upload' ],
134
-			[ 'Kirki\Settings\Repeater', 'Kirki\Settings\Repeater_Setting' ],
135
-			[ 'Kirki\Settings\Repeater', 'Kirki_Settings_Repeater_Setting' ],
136
-			[ 'WP_Customize_Section', 'Kirki_Sections_Default_Section' ],
137
-			[ 'Kirki\Section_Types\Expanded', 'Kirki_Sections_Expanded_Section' ],
138
-			[ 'Kirki\Section_Types\Nested', 'Kirki_Sections_Nested_Section' ],
139
-			[ 'Kirki\Section_Types\Link', 'Kirki_Sections_Link_Section' ],
140
-			[ 'Kirki\Panel_Types\Nested', 'Kirki_Panels_Nested_Panel' ],
141
-		],
142
-	];
22
+    /**
23
+     * An array of class aliases.
24
+     *
25
+     * @access private
26
+     * @since 0.1
27
+     * @var array
28
+     */
29
+    private $aliases = [
30
+        'generic'    => [
31
+            [ 'Kirki\Compatibility\Kirki', 'Kirki' ],
32
+            [ 'Kirki\Compatibility\Config', 'Kirki_Config' ],
33
+            [ 'Kirki\Compatibility\Control', 'Kirki_Control' ],
34
+            [ 'Kirki\Compatibility\Field', 'Kirki_Field' ],
35
+            [ 'Kirki\Util\Helper', 'Kirki_Helper' ],
36
+            [ 'Kirki\Compatibility\Init', 'Kirki_Init' ],
37
+            [ 'Kirki\L10n', 'Kirki_L10n' ],
38
+            [ 'Kirki\Compatibility\Modules', 'Kirki_Modules' ],
39
+            [ 'Kirki\Compatibility\Sanitize_Values', 'Kirki_Sanitize_Values' ],
40
+            [ 'Kirki\Compatibility\Section', 'Kirki_Section' ],
41
+            [ 'Kirki\Compatibility\Values', 'Kirki_Values' ],
42
+            [ 'Kirki\Util\Util', 'Kirki_Util' ],
43
+            [ 'Kirki\Compatibility\Framework', 'Kirki_Toolkit' ],
44
+            [ 'Kirki\Module\CSS', 'Kirki_Modules_CSS' ],
45
+            [ 'Kirki\Module\CSS\Output', 'Kirki_Output' ],
46
+            [ 'Kirki\Module\CSS\Generator', 'Kirki_Modules_CSS_Generator' ],
47
+            [ 'Kirki\Module\CSS\Property', 'Kirki_Output_Property' ],
48
+            [ 'Kirki\Module\CSS\Property\Font_Family', 'Kirki_Output_Property_Font_Family' ],
49
+            [ 'Kirki\Module\Preset', 'Kirki_Modules_Preset' ],
50
+            [ 'Kirki\Module\Tooltips', 'Kirki_Modules_Tooltips' ],
51
+            [ 'Kirki\Module\Webfonts', 'Kirki_Modules_Webfonts' ],
52
+            [ 'Kirki\Module\Webfonts\Google', 'Kirki_Fonts_Google' ],
53
+            [ 'Kirki\Module\Webfonts\Fonts', 'Kirki_Fonts' ],
54
+            [ 'Kirki\Module\Webfonts\Embed', 'Kirki_Modules_Webfonts_Embed' ],
55
+            [ 'Kirki\Module\Webfonts\Async', 'Kirki_Modules_Webfonts_Async' ],
56
+            [ 'Kirki\Module\Field_Dependencies', 'Kirki_Modules_Field_Dependencies' ],
57
+            [ 'Kirki\Module\Editor_Styles', 'Kirki_Modules_Gutenberg' ],
58
+            [ 'Kirki\Module\Selective_Refresh', 'Kirki_Modules_Selective_Refresh' ],
59
+            [ 'Kirki\Module\Postmessage', 'Kirki_Modules_Postmessage' ],
60
+            [ 'Kirki\Field\Background', 'Kirki_Field_Background' ],
61
+            [ 'Kirki\Field\CSS\Background', 'Kirki_Output_Field_Background' ],
62
+            [ 'Kirki\Field\Checkbox', 'Kirki_Field_Checkbox' ],
63
+            [ 'Kirki\Field\Checkbox_Switch', 'Kirki_Field_Switch' ],
64
+            [ 'Kirki\Field\Checkbox_Switch', 'Kirki\Field\Switch' ], // Preventing typo.
65
+            [ 'Kirki\Field\Checkbox_Toggle', 'Kirki_Field_Toggle' ],
66
+            [ 'Kirki\Field\Checkbox_Toggle', 'Kirki\Field\Toggle' ], // Preventing typo.
67
+            [ 'Kirki\Field\Code', 'Kirki_Field_Code' ],
68
+            [ 'Kirki\Field\Color', 'Kirki_Field_Color' ],
69
+            [ 'Kirki\Field\Color', 'Kirki_Field_Color_Alpha' ],
70
+            [ 'Kirki\Field\Color_Palette', 'Kirki_Field_Color_Palette' ],
71
+            [ 'Kirki\Field\Custom', 'Kirki_Field_Custom' ],
72
+            [ 'Kirki\Field\Dashicons', 'Kirki_Field_Dashicons' ],
73
+            [ 'Kirki\Field\Date', 'Kirki_Field_Date' ],
74
+            [ 'Kirki\Field\Dimension', 'Kirki_Field_Dimension' ],
75
+            [ 'Kirki\Field\Dimensions', 'Kirki_Field_Dimensions' ],
76
+            [ 'Kirki\Field\CSS\Dimensions', 'Kirki_Output_Field_Dimensions' ],
77
+            [ 'Kirki\Field\Dimensions', 'Kirki_Field_Spacing' ],
78
+            [ 'Kirki\Field\Dimensions', 'Kirki\Field\Spacing' ],
79
+            [ 'Kirki\Field\Editor', 'Kirki_Field_Editor' ],
80
+            [ 'Kirki\Field\FontAwesome', 'Kirki_Field_FontAwesome' ],
81
+            [ 'Kirki\Field\Generic', 'Kirki_Field_Kirki_Generic' ],
82
+            [ 'Kirki\Field\Generic', 'Kirki_Field_Generic' ],
83
+            [ 'Kirki\Field\Text', 'Kirki_Field_Text' ],
84
+            [ 'Kirki\Field\Textarea', 'Kirki_Field_Textarea' ],
85
+            [ 'Kirki\Field\URL', 'Kirki_Field_URL' ],
86
+            [ 'Kirki\Field\URL', 'Kirki_Field_Link' ],
87
+            [ 'Kirki\Field\URL', 'Kirki\Field\Link' ],
88
+            [ 'Kirki\Field\Image', 'Kirki_Field_Image' ],
89
+            [ 'Kirki\Field\CSS\Image', 'Kirki_Output_Field_Image' ],
90
+            [ 'Kirki\Field\Multicheck', 'Kirki_Field_Multicheck' ],
91
+            [ 'Kirki\Field\Multicolor', 'Kirki_Field_Multicolor' ],
92
+            [ 'Kirki\Field\CSS\Multicolor', 'Kirki_Output_Field_Multicolor' ],
93
+            [ 'Kirki\Field\Number', 'Kirki_Field_Number' ],
94
+            [ 'Kirki\Field\Palette', 'Kirki_Field_Palette' ],
95
+            [ 'Kirki\Field\Repeater', 'Kirki_Field_Repeater' ],
96
+            [ 'Kirki\Field\Dropdown_Pages', 'Kirki_Field_Dropdown_Pages' ],
97
+            [ 'Kirki\Field\Preset', 'Kirki_Field_Preset' ],
98
+            [ 'Kirki\Field\Select', 'Kirki_Field_Select' ],
99
+            [ 'Kirki\Field\Slider', 'Kirki_Field_Slider' ],
100
+            [ 'Kirki\Field\Sortable', 'Kirki_Field_Sortable' ],
101
+            [ 'Kirki\Field\Typography', 'Kirki_Field_Typography' ],
102
+            [ 'Kirki\Field\CSS\Typography', 'Kirki_Output_Field_Typography' ],
103
+            [ 'Kirki\Field\Upload', 'Kirki_Field_Upload' ],
104
+        ],
105
+        'customizer' => [
106
+            [ 'Kirki\Control\Base', 'Kirki_Control_Base' ],
107
+            [ 'Kirki\Control\Base', 'Kirki_Customize_Control' ],
108
+            [ 'Kirki\Control\Checkbox', 'Kirki_Control_Checkbox' ],
109
+            [ 'Kirki\Control\Checkbox_Switch', 'Kirki_Control_Switch' ],
110
+            [ 'Kirki\Control\Checkbox_Toggle', 'Kirki_Control_Toggle' ],
111
+            [ 'WP_Customize_Code_Editor_Control', 'Kirki_Control_Code' ],
112
+            [ 'Kirki\Control\Color', 'Kirki_Control_Color' ],
113
+            [ 'Kirki\Control\Color_Palette', 'Kirki_Control_Color_Palette' ],
114
+            [ 'WP_Customize_Cropped_Image_Control', 'Kirki_Control_Cropped_Image' ],
115
+            [ 'Kirki\Control\Custom', 'Kirki_Control_Custom' ],
116
+            [ 'Kirki\Control\Dashicons', 'Kirki_Control_Dashicons' ],
117
+            [ 'Kirki\Control\Date', 'Kirki_Control_Date' ],
118
+            [ 'Kirki\Control\Dimension', 'Kirki_Control_Dimension' ],
119
+            [ 'Kirki\Control\Editor', 'Kirki_Control_Editor' ],
120
+            [ 'Kirki\Control\Generic', 'Kirki_Control_Generic' ],
121
+            [ 'Kirki\Control\Image', 'Kirki_Control_Image' ],
122
+            [ 'Kirki\Control\Multicheck', 'Kirki_Control_Multicheck' ],
123
+            [ 'Kirki\Control\Generic', 'Kirki_Control_Number' ],
124
+            [ 'Kirki\Control\Palette', 'Kirki_Control_Palette' ],
125
+            [ 'Kirki\Control\Radio', 'Kirki_Control_Radio' ],
126
+            [ 'Kirki\Control\Radio_Buttonset', 'Kirki_Control_Radio_Buttonset' ],
127
+            [ 'Kirki\Control\Radio_Image', 'Kirki_Control_Radio_Image' ],
128
+            [ 'Kirki\Control\Radio_Image', 'Kirki_Controls_Radio_Image_Control' ],
129
+            [ 'Kirki\Control\Repeater', 'Kirki_Control_Repeater' ],
130
+            [ 'Kirki\Control\Select', 'Kirki_Control_Select' ],
131
+            [ 'Kirki\Control\Slider', 'Kirki_Control_Slider' ],
132
+            [ 'Kirki\Control\Sortable', 'Kirki_Control_Sortable' ],
133
+            [ 'Kirki\Control\Upload', 'Kirki_Control_Upload' ],
134
+            [ 'Kirki\Settings\Repeater', 'Kirki\Settings\Repeater_Setting' ],
135
+            [ 'Kirki\Settings\Repeater', 'Kirki_Settings_Repeater_Setting' ],
136
+            [ 'WP_Customize_Section', 'Kirki_Sections_Default_Section' ],
137
+            [ 'Kirki\Section_Types\Expanded', 'Kirki_Sections_Expanded_Section' ],
138
+            [ 'Kirki\Section_Types\Nested', 'Kirki_Sections_Nested_Section' ],
139
+            [ 'Kirki\Section_Types\Link', 'Kirki_Sections_Link_Section' ],
140
+            [ 'Kirki\Panel_Types\Nested', 'Kirki_Panels_Nested_Panel' ],
141
+        ],
142
+    ];
143 143
 
144
-	/**
145
-	 * Constructor.
146
-	 *
147
-	 * @access public
148
-	 * @since 0.1
149
-	 */
150
-	public function __construct() {
151
-		$this->add_aliases();
152
-		add_action( 'customize_register', [ $this, 'add_customizer_aliases' ] );
153
-	}
144
+    /**
145
+     * Constructor.
146
+     *
147
+     * @access public
148
+     * @since 0.1
149
+     */
150
+    public function __construct() {
151
+        $this->add_aliases();
152
+        add_action( 'customize_register', [ $this, 'add_customizer_aliases' ] );
153
+    }
154 154
 
155
-	/**
156
-	 * Adds object aliases.
157
-	 *
158
-	 * @access public
159
-	 * @since 0.1
160
-	 * @return void
161
-	 */
162
-	public function add_aliases() {
163
-		foreach ( $this->aliases['generic'] as $item ) {
164
-			if ( class_exists( $item[0] ) ) {
165
-				class_alias( $item[0], $item[1] );
166
-			}
167
-		}
168
-	}
155
+    /**
156
+     * Adds object aliases.
157
+     *
158
+     * @access public
159
+     * @since 0.1
160
+     * @return void
161
+     */
162
+    public function add_aliases() {
163
+        foreach ( $this->aliases['generic'] as $item ) {
164
+            if ( class_exists( $item[0] ) ) {
165
+                class_alias( $item[0], $item[1] );
166
+            }
167
+        }
168
+    }
169 169
 
170
-	/**
171
-	 * Adds object aliases for classes that get instantiated on customize_register.
172
-	 *
173
-	 * @access public
174
-	 * @since 0.1
175
-	 * @return void
176
-	 */
177
-	public function add_customizer_aliases() {
178
-		foreach ( $this->aliases['customizer'] as $item ) {
179
-			if ( class_exists( $item[0] ) ) {
180
-				class_alias( $item[0], $item[1] );
181
-			}
182
-		}
183
-	}
170
+    /**
171
+     * Adds object aliases for classes that get instantiated on customize_register.
172
+     *
173
+     * @access public
174
+     * @since 0.1
175
+     * @return void
176
+     */
177
+    public function add_customizer_aliases() {
178
+        foreach ( $this->aliases['customizer'] as $item ) {
179
+            if ( class_exists( $item[0] ) ) {
180
+                class_alias( $item[0], $item[1] );
181
+            }
182
+        }
183
+    }
184 184
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/compatibility/src/Scripts.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -21,38 +21,38 @@
 block discarded – undo
21 21
  */
22 22
 class Scripts {
23 23
 
24
-	/**
25
-	 * Constructor.
26
-	 *
27
-	 * @access public
28
-	 * @since 0.1
29
-	 */
30
-	public function __construct() {
31
-		global $wp_version;
24
+    /**
25
+     * Constructor.
26
+     *
27
+     * @access public
28
+     * @since 0.1
29
+     */
30
+    public function __construct() {
31
+        global $wp_version;
32 32
 
33
-		/**
34
-		 * Check if the WordPress version is lower than 5.0
35
-		 * If lower then we need to enqueue the backported scripts.
36
-		 */
37
-		if ( version_compare( $GLOBALS['wp_version'], '5.0', '<' ) ) {
38
-			add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
39
-			add_action( 'admin_register_scripts', [ $this, 'register_scripts' ] );
40
-			add_action( 'customize_controls_enqueue_scripts', [ $this, 'register_scripts' ] );
41
-		}
42
-	}
33
+        /**
34
+         * Check if the WordPress version is lower than 5.0
35
+         * If lower then we need to enqueue the backported scripts.
36
+         */
37
+        if ( version_compare( $GLOBALS['wp_version'], '5.0', '<' ) ) {
38
+            add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] );
39
+            add_action( 'admin_register_scripts', [ $this, 'register_scripts' ] );
40
+            add_action( 'customize_controls_enqueue_scripts', [ $this, 'register_scripts' ] );
41
+        }
42
+    }
43 43
 
44
-	/**
45
-	 * Enqueue missing WP scripts.
46
-	 *
47
-	 * @access public
48
-	 * @since 0.1
49
-	 * @return void
50
-	 */
51
-	public function register_scripts() {
52
-		$folder_url = trailingslashit( URL::get_from_path( __DIR__ ) );
53
-		wp_register_script( 'wp-polyfill', $folder_url . 'scripts/wp-polyfill.js', [], '7.0.0', false );
54
-		wp_register_script( 'wp-hooks', $folder_url . 'scripts/hooks.js', [ 'wp-polyfill' ], '2.2.0', false );
55
-		wp_register_script( 'wp-i18n', $folder_url . 'scripts/i18n.js', [ 'wp-polyfill' ], '3.3.0', false );
56
-	}
44
+    /**
45
+     * Enqueue missing WP scripts.
46
+     *
47
+     * @access public
48
+     * @since 0.1
49
+     * @return void
50
+     */
51
+    public function register_scripts() {
52
+        $folder_url = trailingslashit( URL::get_from_path( __DIR__ ) );
53
+        wp_register_script( 'wp-polyfill', $folder_url . 'scripts/wp-polyfill.js', [], '7.0.0', false );
54
+        wp_register_script( 'wp-hooks', $folder_url . 'scripts/hooks.js', [ 'wp-polyfill' ], '2.2.0', false );
55
+        wp_register_script( 'wp-i18n', $folder_url . 'scripts/i18n.js', [ 'wp-polyfill' ], '3.3.0', false );
56
+    }
57 57
 
58 58
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/compatibility/src/Modules.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -17,144 +17,144 @@
 block discarded – undo
17 17
  */
18 18
 class Modules {
19 19
 
20
-	/**
21
-	 * An array of available modules.
22
-	 *
23
-	 * @static
24
-	 * @access private
25
-	 * @since 3.0.0
26
-	 * @var array
27
-	 */
28
-	private static $modules = [];
29
-
30
-	/**
31
-	 * An array of active modules (objects).
32
-	 *
33
-	 * @static
34
-	 * @access private
35
-	 * @since 3.0.0
36
-	 * @var array
37
-	 */
38
-	private static $active_modules = [];
39
-
40
-	/**
41
-	 * Constructor.
42
-	 *
43
-	 * @access public
44
-	 * @since 3.0.0
45
-	 */
46
-	public function __construct() {
47
-
48
-		add_action( 'after_setup_theme', [ $this, 'setup_default_modules' ], 10 );
49
-		add_action( 'after_setup_theme', [ $this, 'init' ], 11 );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Set the default modules and apply the 'kirki_modules' filter.
55
-	 * In v3.0.35 this method was renamed from default_modules to setup_default_modules,
56
-	 * and its visibility changed from private to public to fix https://github.com/aristath/kirki/issues/2023
57
-	 *
58
-	 * @access public
59
-	 * @since 3.0.0
60
-	 */
61
-	public function setup_default_modules() {
62
-
63
-		self::$modules = apply_filters(
64
-			'kirki_modules',
65
-			[
66
-				'css'                => '\Kirki\Module\CSS',
67
-				'tooltips'           => '\Kirki\Module\Tooltips',
68
-				'postMessage'        => '\Kirki\Module\Postmessage',
69
-				'selective-refresh'  => '\Kirki\Module\Selective_Refresh',
70
-				'field-dependencies' => '\Kirki\Module\Field_Dependencies',
71
-				'webfonts'           => '\Kirki\Module\Webfonts',
72
-				'preset'             => '\Kirki\Module\Preset',
73
-				'gutenberg'          => '\Kirki\Module\Editor_Styles',
74
-				'section-icons'      => '\Kirki\Module\Section_Icons',
75
-			]
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
-
90
-		foreach ( self::$modules as $module_class ) {
91
-			if ( class_exists( $module_class ) ) {
92
-				new $module_class();
93
-			}
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
-
108
-		if ( ! in_array( $module, self::$modules, true ) ) {
109
-			self::$modules[] = $module;
110
-		}
111
-
112
-	}
113
-
114
-	/**
115
-	 * Remove a module.
116
-	 *
117
-	 * @static
118
-	 * @access public
119
-	 * @param string $module The classname of the module to add.
120
-	 * @since 3.0.0
121
-	 */
122
-	public static function remove_module( $module ) {
123
-
124
-		$key = array_search( $module, self::$modules, true );
125
-
126
-		if ( false !== $key ) {
127
-			unset( self::$modules[ $key ] );
128
-		}
129
-
130
-	}
131
-
132
-	/**
133
-	 * Get the modules array.
134
-	 *
135
-	 * @static
136
-	 * @access public
137
-	 * @since 3.0.0
138
-	 * @return array
139
-	 */
140
-	public static function get_modules() {
141
-
142
-		return self::$modules;
143
-
144
-	}
145
-
146
-	/**
147
-	 * Get the array of active modules (objects).
148
-	 *
149
-	 * @static
150
-	 * @access public
151
-	 * @since 3.0.0
152
-	 * @return array
153
-	 */
154
-	public static function get_active_modules() {
155
-
156
-		return self::$active_modules;
157
-
158
-	}
20
+    /**
21
+     * An array of available modules.
22
+     *
23
+     * @static
24
+     * @access private
25
+     * @since 3.0.0
26
+     * @var array
27
+     */
28
+    private static $modules = [];
29
+
30
+    /**
31
+     * An array of active modules (objects).
32
+     *
33
+     * @static
34
+     * @access private
35
+     * @since 3.0.0
36
+     * @var array
37
+     */
38
+    private static $active_modules = [];
39
+
40
+    /**
41
+     * Constructor.
42
+     *
43
+     * @access public
44
+     * @since 3.0.0
45
+     */
46
+    public function __construct() {
47
+
48
+        add_action( 'after_setup_theme', [ $this, 'setup_default_modules' ], 10 );
49
+        add_action( 'after_setup_theme', [ $this, 'init' ], 11 );
50
+
51
+    }
52
+
53
+    /**
54
+     * Set the default modules and apply the 'kirki_modules' filter.
55
+     * In v3.0.35 this method was renamed from default_modules to setup_default_modules,
56
+     * and its visibility changed from private to public to fix https://github.com/aristath/kirki/issues/2023
57
+     *
58
+     * @access public
59
+     * @since 3.0.0
60
+     */
61
+    public function setup_default_modules() {
62
+
63
+        self::$modules = apply_filters(
64
+            'kirki_modules',
65
+            [
66
+                'css'                => '\Kirki\Module\CSS',
67
+                'tooltips'           => '\Kirki\Module\Tooltips',
68
+                'postMessage'        => '\Kirki\Module\Postmessage',
69
+                'selective-refresh'  => '\Kirki\Module\Selective_Refresh',
70
+                'field-dependencies' => '\Kirki\Module\Field_Dependencies',
71
+                'webfonts'           => '\Kirki\Module\Webfonts',
72
+                'preset'             => '\Kirki\Module\Preset',
73
+                'gutenberg'          => '\Kirki\Module\Editor_Styles',
74
+                'section-icons'      => '\Kirki\Module\Section_Icons',
75
+            ]
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
+
90
+        foreach ( self::$modules as $module_class ) {
91
+            if ( class_exists( $module_class ) ) {
92
+                new $module_class();
93
+            }
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
+
108
+        if ( ! in_array( $module, self::$modules, true ) ) {
109
+            self::$modules[] = $module;
110
+        }
111
+
112
+    }
113
+
114
+    /**
115
+     * Remove a module.
116
+     *
117
+     * @static
118
+     * @access public
119
+     * @param string $module The classname of the module to add.
120
+     * @since 3.0.0
121
+     */
122
+    public static function remove_module( $module ) {
123
+
124
+        $key = array_search( $module, self::$modules, true );
125
+
126
+        if ( false !== $key ) {
127
+            unset( self::$modules[ $key ] );
128
+        }
129
+
130
+    }
131
+
132
+    /**
133
+     * Get the modules array.
134
+     *
135
+     * @static
136
+     * @access public
137
+     * @since 3.0.0
138
+     * @return array
139
+     */
140
+    public static function get_modules() {
141
+
142
+        return self::$modules;
143
+
144
+    }
145
+
146
+    /**
147
+     * Get the array of active modules (objects).
148
+     *
149
+     * @static
150
+     * @access public
151
+     * @since 3.0.0
152
+     * @return array
153
+     */
154
+    public static function get_active_modules() {
155
+
156
+        return self::$active_modules;
157
+
158
+    }
159 159
 
160 160
 }
Please login to merge, or discard this patch.
includes/kirki-4.0.24/packages/kirki-framework/compatibility/src/Init.php 1 patch
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -17,241 +17,241 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Init {
19 19
 
20
-	/**
21
-	 * Control types.
22
-	 *
23
-	 * @access private
24
-	 * @since 3.0.0
25
-	 * @var array
26
-	 */
27
-	private $control_types = [];
28
-
29
-	/**
30
-	 * Should we show a nag for the deprecated fontawesome field?
31
-	 *
32
-	 * @static
33
-	 * @access private
34
-	 * @since 3.0.42
35
-	 * @var bool
36
-	 */
37
-	private static $show_fa_nag = false;
38
-
39
-	/**
40
-	 * The class constructor.
41
-	 */
42
-	public function __construct() {
43
-		add_action( 'wp_loaded', [ $this, 'add_to_customizer' ], 1 );
44
-		add_filter( 'kirki_control_types', [ $this, 'default_control_types' ] );
45
-
46
-		add_action( 'customize_register', [ $this, 'remove_controls' ], 99999 );
47
-
48
-		add_action( 'admin_notices', [ $this, 'admin_notices' ] );
49
-		add_action( 'admin_init', [ $this, 'dismiss_nag' ] );
50
-
51
-		// ? Bagus: is this necessary? The Values class doesn't have constructor, so this does nothing.
52
-		new Values();
53
-	}
54
-
55
-	/**
56
-	 * Add the default Kirki control types.
57
-	 *
58
-	 * @access public
59
-	 * @since 3.0.0
60
-	 * @param array $control_types The control types array.
61
-	 * @return array
62
-	 */
63
-	public function default_control_types( $control_types = [] ) {
64
-		$this->control_types = [
65
-			'kirki-composite'       => '\Kirki\Control\Composite',
66
-			'checkbox'              => '\Kirki\Control\Checkbox',
67
-			'kirki-color'           => '\Kirki\Control\ReactColorful',
68
-			'kirki-color-palette'   => '\Kirki\Control\Color_Palette',
69
-			'kirki-custom'          => '\Kirki\Control\Custom',
70
-			'kirki-date'            => '\Kirki\Control\Date',
71
-			'kirki-dashicons'       => '\Kirki\Control\Dashicons',
72
-			'kirki-dimension'       => '\Kirki\Control\Dimension',
73
-			'kirki-dimensions'      => '\Kirki\Control\Dimensions',
74
-			'kirki-editor'          => '\Kirki\Control\Editor',
75
-			'kirki-image'           => '\Kirki\Control\Image',
76
-			'kirki-multicolor'      => '\Kirki\Control\Multicolor',
77
-			'kirki-multicheck'      => '\Kirki\Control\Multicheck',
78
-			'kirki-number'          => '\Kirki\Control\Number',
79
-			'kirki-radio'           => '\Kirki\Control\Radio',
80
-			'kirki-radio-buttonset' => '\Kirki\Control\Radio_Buttonset',
81
-			'kirki-radio-image'     => '\Kirki\Control\Radio_Image',
82
-			'repeater'              => '\Kirki\Control\Repeater',
83
-			'kirki-select'          => '\Kirki\Control\Select',
84
-			'kirki-slider'          => '\Kirki\Control\Slider',
85
-			'kirki-sortable'        => '\Kirki\Control\Sortable',
86
-			'kirki-spacing'         => '\Kirki\Control\Dimensions',
87
-			'kirki-switch'          => '\Kirki\Control\Checkbox_Switch',
88
-			'kirki-generic'         => '\Kirki\Control\Generic',
89
-			'kirki-toggle'          => '\Kirki\Control\Checkbox_Toggle',
90
-			'image'                 => '\Kirki\Control\Image',
91
-			'cropped_image'         => '\Kirki\Control\Cropped_Image',
92
-			'upload'                => '\Kirki\Control\Upload',
93
-		];
94
-		return array_merge( $this->control_types, $control_types );
95
-	}
96
-
97
-	/**
98
-	 * Helper function that adds the fields to the customizer.
99
-	 */
100
-	public function add_to_customizer() {
101
-		$this->fields_from_filters();
102
-		add_action( 'customize_register', [ $this, 'register_control_types' ] );
103
-		add_action( 'customize_register', [ $this, 'add_fields' ], 99 );
104
-	}
105
-
106
-	/**
107
-	 * Register control types
108
-	 */
109
-	public function register_control_types() {
110
-		global $wp_customize;
111
-
112
-		$this->control_types = $this->default_control_types();
113
-		if ( ! class_exists( 'WP_Customize_Code_Editor_Control' ) ) {
114
-			unset( $this->control_types['code_editor'] );
115
-		}
116
-		foreach ( $this->control_types as $key => $classname ) {
117
-			if ( ! class_exists( $classname ) ) {
118
-				unset( $this->control_types[ $key ] );
119
-			}
120
-		}
121
-
122
-		$skip_control_types = apply_filters(
123
-			'kirki_control_types_exclude',
124
-			[
125
-				'\Kirki\Control\Repeater',
126
-				'\WP_Customize_Control',
127
-			]
128
-		);
129
-
130
-		foreach ( $this->control_types as $control_type ) {
131
-			if ( ! in_array( $control_type, $skip_control_types, true ) && class_exists( $control_type ) ) {
132
-				$wp_customize->register_control_type( $control_type );
133
-			}
134
-		}
135
-	}
136
-
137
-	/**
138
-	 * Create the settings and controls from the $fields array and register them.
139
-	 *
140
-	 * @var object The WordPress Customizer object.
141
-	 */
142
-	public function add_fields() {
143
-		global $wp_customize;
144
-
145
-		foreach ( Kirki::$fields as $args ) {
146
-
147
-			// Create the settings.
148
-			new \Kirki\Compatibility\Settings( $args );
149
-
150
-			// Check if we're on the customizer.
151
-			// If we are, then we will create the controls, add the scripts needed for the customizer
152
-			// and any other tweaks that this field may require.
153
-			if ( $wp_customize ) {
154
-
155
-				// Create the control.
156
-				new Control( $args );
157
-
158
-			}
159
-		}
160
-	}
161
-
162
-	/**
163
-	 * Process fields added using the 'kirki_fields' and 'kirki_controls' filter.
164
-	 * These filters are no longer used, this is simply for backwards-compatibility.
165
-	 *
166
-	 * @access private
167
-	 * @since 2.0.0
168
-	 */
169
-	private function fields_from_filters() {
170
-		$fields = apply_filters( 'kirki_controls', [] );
171
-		$fields = apply_filters( 'kirki_fields', $fields );
172
-
173
-		if ( ! empty( $fields ) ) {
174
-			foreach ( $fields as $field ) {
175
-				$field['kirki_config'] = 'global';
176
-				Kirki::add_field( 'global', $field );
177
-			}
178
-		}
179
-	}
180
-
181
-	/**
182
-	 * Alias for the is_plugin static method in the Kirki\Util\Util class.
183
-	 * This is here for backwards-compatibility purposes.
184
-	 *
185
-	 * @static
186
-	 * @access public
187
-	 * @since 3.0.0
188
-	 * @return bool
189
-	 */
190
-	public static function is_plugin() {
191
-		return Util::is_plugin();
192
-	}
193
-
194
-	/**
195
-	 * Alias for the get_variables static method in the Kirki\Util\Util class.
196
-	 * This is here for backwards-compatibility purposes.
197
-	 *
198
-	 * @static
199
-	 * @access public
200
-	 * @since 2.0.0
201
-	 * @return array Formatted as array( 'variable-name' => value ).
202
-	 */
203
-	public static function get_variables() {
204
-
205
-		// Log error for developers.
206
-		_doing_it_wrong( __METHOD__, esc_html__( 'We detected you\'re using Kirki\Compatibility\Init::get_variables(). Please use \Kirki\Util\Util::get_variables() instead.', 'kirki' ), '3.0.10' );
207
-
208
-		// ! This will be failed, because Util class is under Kirki\Util namespace.
209
-		return Util::get_variables();
210
-	}
211
-
212
-	/**
213
-	 * Remove controls.
214
-	 *
215
-	 * @since 3.0.17
216
-	 * @param object $wp_customize The customizer object.
217
-	 * @return void
218
-	 */
219
-	public function remove_controls( $wp_customize ) {
220
-		foreach ( Kirki::$controls_to_remove as $control ) {
221
-			$wp_customize->remove_control( $control );
222
-		}
223
-	}
224
-
225
-	/**
226
-	 * Shows an admin notice.
227
-	 *
228
-	 * @access public
229
-	 * @since 3.0.42
230
-	 * @return void
231
-	 */
232
-	public function admin_notices() {
233
-
234
-		// No need for a nag if we don't need to recommend installing the FA plugin.
235
-		if ( ! self::$show_fa_nag ) {
236
-			return;
237
-		}
238
-
239
-		// No need for a nag if FA plugin is already installed.
240
-		if ( defined( 'FONTAWESOME_DIR_PATH' ) ) {
241
-			return;
242
-		}
243
-
244
-		// No need for a nag if current user can't install plugins.
245
-		if ( ! current_user_can( 'install_plugins' ) ) {
246
-			return;
247
-		}
248
-
249
-		// No need for a nag if user has dismissed it.
250
-		$dismissed = get_user_meta( get_current_user_id(), 'kirki_fa_nag_dismissed', true );
251
-		if ( true === $dismissed || 1 === $dismissed || '1' === $dismissed ) {
252
-			return;
253
-		}
254
-		?>
20
+    /**
21
+     * Control types.
22
+     *
23
+     * @access private
24
+     * @since 3.0.0
25
+     * @var array
26
+     */
27
+    private $control_types = [];
28
+
29
+    /**
30
+     * Should we show a nag for the deprecated fontawesome field?
31
+     *
32
+     * @static
33
+     * @access private
34
+     * @since 3.0.42
35
+     * @var bool
36
+     */
37
+    private static $show_fa_nag = false;
38
+
39
+    /**
40
+     * The class constructor.
41
+     */
42
+    public function __construct() {
43
+        add_action( 'wp_loaded', [ $this, 'add_to_customizer' ], 1 );
44
+        add_filter( 'kirki_control_types', [ $this, 'default_control_types' ] );
45
+
46
+        add_action( 'customize_register', [ $this, 'remove_controls' ], 99999 );
47
+
48
+        add_action( 'admin_notices', [ $this, 'admin_notices' ] );
49
+        add_action( 'admin_init', [ $this, 'dismiss_nag' ] );
50
+
51
+        // ? Bagus: is this necessary? The Values class doesn't have constructor, so this does nothing.
52
+        new Values();
53
+    }
54
+
55
+    /**
56
+     * Add the default Kirki control types.
57
+     *
58
+     * @access public
59
+     * @since 3.0.0
60
+     * @param array $control_types The control types array.
61
+     * @return array
62
+     */
63
+    public function default_control_types( $control_types = [] ) {
64
+        $this->control_types = [
65
+            'kirki-composite'       => '\Kirki\Control\Composite',
66
+            'checkbox'              => '\Kirki\Control\Checkbox',
67
+            'kirki-color'           => '\Kirki\Control\ReactColorful',
68
+            'kirki-color-palette'   => '\Kirki\Control\Color_Palette',
69
+            'kirki-custom'          => '\Kirki\Control\Custom',
70
+            'kirki-date'            => '\Kirki\Control\Date',
71
+            'kirki-dashicons'       => '\Kirki\Control\Dashicons',
72
+            'kirki-dimension'       => '\Kirki\Control\Dimension',
73
+            'kirki-dimensions'      => '\Kirki\Control\Dimensions',
74
+            'kirki-editor'          => '\Kirki\Control\Editor',
75
+            'kirki-image'           => '\Kirki\Control\Image',
76
+            'kirki-multicolor'      => '\Kirki\Control\Multicolor',
77
+            'kirki-multicheck'      => '\Kirki\Control\Multicheck',
78
+            'kirki-number'          => '\Kirki\Control\Number',
79
+            'kirki-radio'           => '\Kirki\Control\Radio',
80
+            'kirki-radio-buttonset' => '\Kirki\Control\Radio_Buttonset',
81
+            'kirki-radio-image'     => '\Kirki\Control\Radio_Image',
82
+            'repeater'              => '\Kirki\Control\Repeater',
83
+            'kirki-select'          => '\Kirki\Control\Select',
84
+            'kirki-slider'          => '\Kirki\Control\Slider',
85
+            'kirki-sortable'        => '\Kirki\Control\Sortable',
86
+            'kirki-spacing'         => '\Kirki\Control\Dimensions',
87
+            'kirki-switch'          => '\Kirki\Control\Checkbox_Switch',
88
+            'kirki-generic'         => '\Kirki\Control\Generic',
89
+            'kirki-toggle'          => '\Kirki\Control\Checkbox_Toggle',
90
+            'image'                 => '\Kirki\Control\Image',
91
+            'cropped_image'         => '\Kirki\Control\Cropped_Image',
92
+            'upload'                => '\Kirki\Control\Upload',
93
+        ];
94
+        return array_merge( $this->control_types, $control_types );
95
+    }
96
+
97
+    /**
98
+     * Helper function that adds the fields to the customizer.
99
+     */
100
+    public function add_to_customizer() {
101
+        $this->fields_from_filters();
102
+        add_action( 'customize_register', [ $this, 'register_control_types' ] );
103
+        add_action( 'customize_register', [ $this, 'add_fields' ], 99 );
104
+    }
105
+
106
+    /**
107
+     * Register control types
108
+     */
109
+    public function register_control_types() {
110
+        global $wp_customize;
111
+
112
+        $this->control_types = $this->default_control_types();
113
+        if ( ! class_exists( 'WP_Customize_Code_Editor_Control' ) ) {
114
+            unset( $this->control_types['code_editor'] );
115
+        }
116
+        foreach ( $this->control_types as $key => $classname ) {
117
+            if ( ! class_exists( $classname ) ) {
118
+                unset( $this->control_types[ $key ] );
119
+            }
120
+        }
121
+
122
+        $skip_control_types = apply_filters(
123
+            'kirki_control_types_exclude',
124
+            [
125
+                '\Kirki\Control\Repeater',
126
+                '\WP_Customize_Control',
127
+            ]
128
+        );
129
+
130
+        foreach ( $this->control_types as $control_type ) {
131
+            if ( ! in_array( $control_type, $skip_control_types, true ) && class_exists( $control_type ) ) {
132
+                $wp_customize->register_control_type( $control_type );
133
+            }
134
+        }
135
+    }
136
+
137
+    /**
138
+     * Create the settings and controls from the $fields array and register them.
139
+     *
140
+     * @var object The WordPress Customizer object.
141
+     */
142
+    public function add_fields() {
143
+        global $wp_customize;
144
+
145
+        foreach ( Kirki::$fields as $args ) {
146
+
147
+            // Create the settings.
148
+            new \Kirki\Compatibility\Settings( $args );
149
+
150
+            // Check if we're on the customizer.
151
+            // If we are, then we will create the controls, add the scripts needed for the customizer
152
+            // and any other tweaks that this field may require.
153
+            if ( $wp_customize ) {
154
+
155
+                // Create the control.
156
+                new Control( $args );
157
+
158
+            }
159
+        }
160
+    }
161
+
162
+    /**
163
+     * Process fields added using the 'kirki_fields' and 'kirki_controls' filter.
164
+     * These filters are no longer used, this is simply for backwards-compatibility.
165
+     *
166
+     * @access private
167
+     * @since 2.0.0
168
+     */
169
+    private function fields_from_filters() {
170
+        $fields = apply_filters( 'kirki_controls', [] );
171
+        $fields = apply_filters( 'kirki_fields', $fields );
172
+
173
+        if ( ! empty( $fields ) ) {
174
+            foreach ( $fields as $field ) {
175
+                $field['kirki_config'] = 'global';
176
+                Kirki::add_field( 'global', $field );
177
+            }
178
+        }
179
+    }
180
+
181
+    /**
182
+     * Alias for the is_plugin static method in the Kirki\Util\Util class.
183
+     * This is here for backwards-compatibility purposes.
184
+     *
185
+     * @static
186
+     * @access public
187
+     * @since 3.0.0
188
+     * @return bool
189
+     */
190
+    public static function is_plugin() {
191
+        return Util::is_plugin();
192
+    }
193
+
194
+    /**
195
+     * Alias for the get_variables static method in the Kirki\Util\Util class.
196
+     * This is here for backwards-compatibility purposes.
197
+     *
198
+     * @static
199
+     * @access public
200
+     * @since 2.0.0
201
+     * @return array Formatted as array( 'variable-name' => value ).
202
+     */
203
+    public static function get_variables() {
204
+
205
+        // Log error for developers.
206
+        _doing_it_wrong( __METHOD__, esc_html__( 'We detected you\'re using Kirki\Compatibility\Init::get_variables(). Please use \Kirki\Util\Util::get_variables() instead.', 'kirki' ), '3.0.10' );
207
+
208
+        // ! This will be failed, because Util class is under Kirki\Util namespace.
209
+        return Util::get_variables();
210
+    }
211
+
212
+    /**
213
+     * Remove controls.
214
+     *
215
+     * @since 3.0.17
216
+     * @param object $wp_customize The customizer object.
217
+     * @return void
218
+     */
219
+    public function remove_controls( $wp_customize ) {
220
+        foreach ( Kirki::$controls_to_remove as $control ) {
221
+            $wp_customize->remove_control( $control );
222
+        }
223
+    }
224
+
225
+    /**
226
+     * Shows an admin notice.
227
+     *
228
+     * @access public
229
+     * @since 3.0.42
230
+     * @return void
231
+     */
232
+    public function admin_notices() {
233
+
234
+        // No need for a nag if we don't need to recommend installing the FA plugin.
235
+        if ( ! self::$show_fa_nag ) {
236
+            return;
237
+        }
238
+
239
+        // No need for a nag if FA plugin is already installed.
240
+        if ( defined( 'FONTAWESOME_DIR_PATH' ) ) {
241
+            return;
242
+        }
243
+
244
+        // No need for a nag if current user can't install plugins.
245
+        if ( ! current_user_can( 'install_plugins' ) ) {
246
+            return;
247
+        }
248
+
249
+        // No need for a nag if user has dismissed it.
250
+        $dismissed = get_user_meta( get_current_user_id(), 'kirki_fa_nag_dismissed', true );
251
+        if ( true === $dismissed || 1 === $dismissed || '1' === $dismissed ) {
252
+            return;
253
+        }
254
+        ?>
255 255
 		<div class="notice notice-info is-dismissible">
256 256
 			<p>
257 257
 				<?php esc_html_e( 'Your theme uses a Font Awesome field for icons. To avoid issues with missing icons on your frontend we recommend you install the official Font Awesome plugin.', 'kirki' ); ?>
@@ -262,49 +262,49 @@  discard block
 block discarded – undo
262 262
 			</p>
263 263
 		</div>
264 264
 		<?php
265
-	}
266
-
267
-	/**
268
-	 * Dismisses the nag.
269
-	 *
270
-	 * @access public
271
-	 * @since 3.0.42
272
-	 * @return void
273
-	 */
274
-	public function dismiss_nag() {
275
-		if ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'kirki-dismiss-nag' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
276
-			if ( get_current_user_id() && isset( $_GET['dismiss-nag'] ) && 'font-awesome-kirki' === $_GET['dismiss-nag'] ) {
277
-				update_user_meta( get_current_user_id(), 'kirki_fa_nag_dismissed', true );
278
-			}
279
-		}
280
-	}
281
-
282
-	/**
283
-	 * Handles showing a nag if the theme is using the deprecated fontawesome field
284
-	 *
285
-	 * @static
286
-	 * @access protected
287
-	 * @since 3.0.42
288
-	 * @param array $args The field arguments.
289
-	 * @return void
290
-	 */
291
-	protected static function maybe_show_fontawesome_nag( $args ) {
292
-
293
-		// If we already know we want it, skip check.
294
-		if ( self::$show_fa_nag ) {
295
-			return;
296
-		}
297
-
298
-		// Check if the field is fontawesome.
299
-		if ( isset( $args['type'] ) && in_array( $args['type'], [ 'fontawesome', 'kirki-fontawesome' ], true ) ) {
300
-
301
-			// Skip check if theme has disabled FA enqueueing via a filter.
302
-			if ( ! apply_filters( 'kirki_load_fontawesome', true ) ) {
303
-				return;
304
-			}
305
-
306
-			// If we got this far, we need to show the nag.
307
-			self::$show_fa_nag = true;
308
-		}
309
-	}
265
+    }
266
+
267
+    /**
268
+     * Dismisses the nag.
269
+     *
270
+     * @access public
271
+     * @since 3.0.42
272
+     * @return void
273
+     */
274
+    public function dismiss_nag() {
275
+        if ( isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'kirki-dismiss-nag' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
276
+            if ( get_current_user_id() && isset( $_GET['dismiss-nag'] ) && 'font-awesome-kirki' === $_GET['dismiss-nag'] ) {
277
+                update_user_meta( get_current_user_id(), 'kirki_fa_nag_dismissed', true );
278
+            }
279
+        }
280
+    }
281
+
282
+    /**
283
+     * Handles showing a nag if the theme is using the deprecated fontawesome field
284
+     *
285
+     * @static
286
+     * @access protected
287
+     * @since 3.0.42
288
+     * @param array $args The field arguments.
289
+     * @return void
290
+     */
291
+    protected static function maybe_show_fontawesome_nag( $args ) {
292
+
293
+        // If we already know we want it, skip check.
294
+        if ( self::$show_fa_nag ) {
295
+            return;
296
+        }
297
+
298
+        // Check if the field is fontawesome.
299
+        if ( isset( $args['type'] ) && in_array( $args['type'], [ 'fontawesome', 'kirki-fontawesome' ], true ) ) {
300
+
301
+            // Skip check if theme has disabled FA enqueueing via a filter.
302
+            if ( ! apply_filters( 'kirki_load_fontawesome', true ) ) {
303
+                return;
304
+            }
305
+
306
+            // If we got this far, we need to show the nag.
307
+            self::$show_fa_nag = true;
308
+        }
309
+    }
310 310
 }
Please login to merge, or discard this patch.