Passed
Push — main ( 137754...ffd9e1 )
by TARIQ
04:53
created
packages/kirki-framework/control-react-select/src/Field/ReactSelect.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -19,183 +19,183 @@
 block discarded – undo
19 19
  */
20 20
 class ReactSelect extends Field {
21 21
 
22
-	/**
23
-	 * The field type.
24
-	 *
25
-	 * @access public
26
-	 * @since 1.0
27
-	 * @var string
28
-	 */
29
-	public $type = 'kirki-select';
30
-
31
-	/**
32
-	 * Whether this is a multi-select or not.
33
-	 *
34
-	 * *Backwards compatibility note:
35
-	 *
36
-	 * Previously (when Kirki used Select2), $multiple is used to:
37
-	 * - Determine whether the select is multiple or not.
38
-	 * - Determine the maximum number of selection.
39
-	 *
40
-	 * Start from Kirki 4 (when Kirki uses react-select),
41
-	 * $multiple is used to determine whether the select is multiple or not.
42
-	 * The maximum selection number is now set in $max_selection.
43
-	 *
44
-	 * @since 1.0
45
-	 * @var bool
46
-	 */
47
-	protected $multiple = false;
48
-
49
-	/**
50
-	 * The maximum selection length for multiple selection.
51
-	 *
52
-	 * @since 1.1
53
-	 * @var bool
54
-	 */
55
-	protected $max_selection_number = 999;
56
-
57
-	/**
58
-	 * Placeholder text.
59
-	 *
60
-	 * @access protected
61
-	 * @since 1.0
62
-	 * @var string|false
63
-	 */
64
-	protected $placeholder = false;
65
-
66
-	/**
67
-	 * The control class-name.
68
-	 *
69
-	 * @access protected
70
-	 * @since 0.1
71
-	 * @var string
72
-	 */
73
-	protected $control_class = '\Kirki\Control\ReactSelect';
74
-
75
-	/**
76
-	 * Whether we should register the control class for JS-templating or not.
77
-	 *
78
-	 * @access protected
79
-	 * @since 0.1
80
-	 * @var bool
81
-	 */
82
-	protected $control_has_js_template = true;
83
-
84
-	/**
85
-	 * Filter arguments before creating the setting.
86
-	 *
87
-	 * @access public
88
-	 * @since 0.1
89
-	 * @param array                $args         The field arguments.
90
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
91
-	 * @return array
92
-	 */
93
-	public function filter_setting_args( $args, $wp_customize ) {
94
-
95
-		if ( $args['settings'] === $this->args['settings'] ) {
96
-			$args = parent::filter_setting_args( $args, $wp_customize );
97
-
98
-			if ( isset( $args['multiple'] ) ) {
99
-				$multiple_and_max             = self::get_multiple_and_max( $args['multiple'] );
100
-				$args['multiple']             = $multiple_and_max['multiple'];
101
-				$args['max_selection_number'] = $multiple_and_max['max_selection_number'];
102
-			} else {
103
-				$args['multiple'] = false;
104
-			}
105
-
106
-			// Set the sanitize-callback if none is defined.
107
-			if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
108
-				$args['sanitize_callback'] = ! $args['multiple'] ? 'sanitize_text_field' : function( $values ) use ( $args ) {
109
-					$values           = (array) $values;
110
-					$sanitized_values = [];
111
-
112
-					// If total selected values > max_selection_number, then we need to remove the excess.
113
-					if ( count( $values ) > $args['max_selection_number'] ) {
114
-						for ( $i = 0; $i < $args['max_selection_number']; $i++ ) {
115
-							$sanitized_values[ $i ] = isset( $values[ $i ] ) ? sanitize_text_field( $values[ $i ] ) : '';
116
-						}
117
-					} else {
118
-						foreach ( $values as $index => $subvalue ) {
119
-							$sanitized_values[ $index ] = sanitize_text_field( $subvalue );
120
-						}
121
-					}
122
-
123
-					return $sanitized_values;
124
-				};
125
-			}
126
-		}
127
-
128
-		return $args;
129
-
130
-	}
131
-
132
-	/**
133
-	 * Filter arguments before creating the control.
134
-	 *
135
-	 * @access public
136
-	 * @since 0.1
137
-	 * @param array                $args         The field arguments.
138
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
139
-	 * @return array
140
-	 */
141
-	public function filter_control_args( $args, $wp_customize ) {
142
-
143
-		if ( $args['settings'] === $this->args['settings'] ) {
144
-			$args = parent::filter_control_args( $args, $wp_customize );
145
-
146
-			if ( isset( $args['multiple'] ) ) {
147
-				$multiple_and_max             = self::get_multiple_and_max( $args['multiple'] );
148
-				$args['multiple']             = $multiple_and_max['multiple'];
149
-				$args['max_selection_number'] = $multiple_and_max['max_selection_number'];
150
-			}
151
-
152
-			$args['type'] = 'kirki-react-select';
153
-		}
154
-
155
-		return $args;
156
-
157
-	}
158
-
159
-	/**
160
-	 * Get the value of "multiple" and "max_selection_number"
161
-	 * from the provided $multiple parameter.
162
-	 *
163
-	 * @since 1.1
164
-	 *
165
-	 * @param bool|int $multiple The provided $multiple value.
166
-	 * @return array
167
-	 */
168
-	public static function get_multiple_and_max( $multiple ) {
169
-
170
-		$max_selection_number = 999;
171
-
172
-		if ( is_numeric( $multiple ) ) {
173
-			$multiple = (int) $multiple;
174
-
175
-			/**
176
-			 * Treat -1 as unlimited just like in WordPress's get_posts (well, in this Kirki case, it's 999 :).
177
-			 * Also treat 0 as "unlimited" because 1 it self will disable the multiple selection.
178
-			 */
179
-			if ( 0 >= $multiple ) {
180
-				$max_selection_number = 999;
181
-				$multiple             = true;
182
-			} else {
183
-				// If $multiple is > 1.
184
-				if ( 1 < $multiple ) {
185
-					$max_selection_number = $multiple;
186
-					$multiple             = true;
187
-				} else {
188
-					// Here $multiple === 1, that means, it's single mode select.
189
-					$multiple = false;
190
-				}
191
-			}
192
-		}
193
-
194
-		return [
195
-			'multiple'             => $multiple,
196
-			'max_selection_number' => $max_selection_number,
197
-		];
198
-
199
-	}
22
+    /**
23
+     * The field type.
24
+     *
25
+     * @access public
26
+     * @since 1.0
27
+     * @var string
28
+     */
29
+    public $type = 'kirki-select';
30
+
31
+    /**
32
+     * Whether this is a multi-select or not.
33
+     *
34
+     * *Backwards compatibility note:
35
+     *
36
+     * Previously (when Kirki used Select2), $multiple is used to:
37
+     * - Determine whether the select is multiple or not.
38
+     * - Determine the maximum number of selection.
39
+     *
40
+     * Start from Kirki 4 (when Kirki uses react-select),
41
+     * $multiple is used to determine whether the select is multiple or not.
42
+     * The maximum selection number is now set in $max_selection.
43
+     *
44
+     * @since 1.0
45
+     * @var bool
46
+     */
47
+    protected $multiple = false;
48
+
49
+    /**
50
+     * The maximum selection length for multiple selection.
51
+     *
52
+     * @since 1.1
53
+     * @var bool
54
+     */
55
+    protected $max_selection_number = 999;
56
+
57
+    /**
58
+     * Placeholder text.
59
+     *
60
+     * @access protected
61
+     * @since 1.0
62
+     * @var string|false
63
+     */
64
+    protected $placeholder = false;
65
+
66
+    /**
67
+     * The control class-name.
68
+     *
69
+     * @access protected
70
+     * @since 0.1
71
+     * @var string
72
+     */
73
+    protected $control_class = '\Kirki\Control\ReactSelect';
74
+
75
+    /**
76
+     * Whether we should register the control class for JS-templating or not.
77
+     *
78
+     * @access protected
79
+     * @since 0.1
80
+     * @var bool
81
+     */
82
+    protected $control_has_js_template = true;
83
+
84
+    /**
85
+     * Filter arguments before creating the setting.
86
+     *
87
+     * @access public
88
+     * @since 0.1
89
+     * @param array                $args         The field arguments.
90
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
91
+     * @return array
92
+     */
93
+    public function filter_setting_args( $args, $wp_customize ) {
94
+
95
+        if ( $args['settings'] === $this->args['settings'] ) {
96
+            $args = parent::filter_setting_args( $args, $wp_customize );
97
+
98
+            if ( isset( $args['multiple'] ) ) {
99
+                $multiple_and_max             = self::get_multiple_and_max( $args['multiple'] );
100
+                $args['multiple']             = $multiple_and_max['multiple'];
101
+                $args['max_selection_number'] = $multiple_and_max['max_selection_number'];
102
+            } else {
103
+                $args['multiple'] = false;
104
+            }
105
+
106
+            // Set the sanitize-callback if none is defined.
107
+            if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
108
+                $args['sanitize_callback'] = ! $args['multiple'] ? 'sanitize_text_field' : function( $values ) use ( $args ) {
109
+                    $values           = (array) $values;
110
+                    $sanitized_values = [];
111
+
112
+                    // If total selected values > max_selection_number, then we need to remove the excess.
113
+                    if ( count( $values ) > $args['max_selection_number'] ) {
114
+                        for ( $i = 0; $i < $args['max_selection_number']; $i++ ) {
115
+                            $sanitized_values[ $i ] = isset( $values[ $i ] ) ? sanitize_text_field( $values[ $i ] ) : '';
116
+                        }
117
+                    } else {
118
+                        foreach ( $values as $index => $subvalue ) {
119
+                            $sanitized_values[ $index ] = sanitize_text_field( $subvalue );
120
+                        }
121
+                    }
122
+
123
+                    return $sanitized_values;
124
+                };
125
+            }
126
+        }
127
+
128
+        return $args;
129
+
130
+    }
131
+
132
+    /**
133
+     * Filter arguments before creating the control.
134
+     *
135
+     * @access public
136
+     * @since 0.1
137
+     * @param array                $args         The field arguments.
138
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
139
+     * @return array
140
+     */
141
+    public function filter_control_args( $args, $wp_customize ) {
142
+
143
+        if ( $args['settings'] === $this->args['settings'] ) {
144
+            $args = parent::filter_control_args( $args, $wp_customize );
145
+
146
+            if ( isset( $args['multiple'] ) ) {
147
+                $multiple_and_max             = self::get_multiple_and_max( $args['multiple'] );
148
+                $args['multiple']             = $multiple_and_max['multiple'];
149
+                $args['max_selection_number'] = $multiple_and_max['max_selection_number'];
150
+            }
151
+
152
+            $args['type'] = 'kirki-react-select';
153
+        }
154
+
155
+        return $args;
156
+
157
+    }
158
+
159
+    /**
160
+     * Get the value of "multiple" and "max_selection_number"
161
+     * from the provided $multiple parameter.
162
+     *
163
+     * @since 1.1
164
+     *
165
+     * @param bool|int $multiple The provided $multiple value.
166
+     * @return array
167
+     */
168
+    public static function get_multiple_and_max( $multiple ) {
169
+
170
+        $max_selection_number = 999;
171
+
172
+        if ( is_numeric( $multiple ) ) {
173
+            $multiple = (int) $multiple;
174
+
175
+            /**
176
+             * Treat -1 as unlimited just like in WordPress's get_posts (well, in this Kirki case, it's 999 :).
177
+             * Also treat 0 as "unlimited" because 1 it self will disable the multiple selection.
178
+             */
179
+            if ( 0 >= $multiple ) {
180
+                $max_selection_number = 999;
181
+                $multiple             = true;
182
+            } else {
183
+                // If $multiple is > 1.
184
+                if ( 1 < $multiple ) {
185
+                    $max_selection_number = $multiple;
186
+                    $multiple             = true;
187
+                } else {
188
+                    // Here $multiple === 1, that means, it's single mode select.
189
+                    $multiple = false;
190
+                }
191
+            }
192
+        }
193
+
194
+        return [
195
+            'multiple'             => $multiple,
196
+            'max_selection_number' => $max_selection_number,
197
+        ];
198
+
199
+    }
200 200
 
201 201
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-react-select/src/Control/ReactSelect.php 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -20,155 +20,155 @@
 block discarded – undo
20 20
  */
21 21
 class ReactSelect extends Base {
22 22
 
23
-	/**
24
-	 * The control type.
25
-	 *
26
-	 * @access public
27
-	 * @since 1.0
28
-	 * @var string
29
-	 */
30
-	public $type = 'kirki-react-select';
31
-
32
-	/**
33
-	 * Placeholder text.
34
-	 *
35
-	 * @access public
36
-	 * @since 1.0
37
-	 * @var string|false
38
-	 */
39
-	public $placeholder = false;
40
-
41
-	/**
42
-	 * Whether the select should be clearable or not.
43
-	 *
44
-	 * @since 1.0
45
-	 * @var bool
46
-	 */
47
-	public $clearable = false;
48
-
49
-	/**
50
-	 * Whether this is a multi-select or not.
51
-	 *
52
-	 * *Backwards compatibility note:
53
-	 *
54
-	 * Previously (when Kirki used Select2), $multiple is used to:
55
-	 * - Determine whether the select is multiple or not.
56
-	 * - Determine the maximum number of selection.
57
-	 *
58
-	 * Start from Kirki 4 (when Kirki uses react-select),
59
-	 * $multiple is used to determine whether the select is multiple or not.
60
-	 * The maximum selection number is now set in $max_selection.
61
-	 *
62
-	 * @access public
63
-	 * @since 1.0
64
-	 * @var bool
65
-	 */
66
-	public $multiple = false;
67
-
68
-	/**
69
-	 * The maximum selection length for multiple selection.
70
-	 *
71
-	 * @access public
72
-	 * @since 1.1
73
-	 * @var bool
74
-	 */
75
-	public $max_selection_number = 999;
76
-
77
-	/**
78
-	 * The version. Used in scripts & styles for cache-busting.
79
-	 *
80
-	 * @static
81
-	 * @access public
82
-	 * @since 1.0
83
-	 * @var string
84
-	 */
85
-	public static $control_ver = '1.1.5';
86
-
87
-	/**
88
-	 * Enqueue control related scripts/styles.
89
-	 *
90
-	 * @access public
91
-	 * @since 1.0
92
-	 * @return void
93
-	 */
94
-	public function enqueue() {
95
-
96
-		parent::enqueue();
97
-
98
-		// Enqueue the script.
99
-		wp_enqueue_script(
100
-			'kirki-control-select',
101
-			URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ),
102
-			[
103
-				'customize-controls',
104
-				'customize-base',
105
-				'wp-element',
106
-				'wp-compose',
107
-				'wp-components',
108
-				'jquery',
109
-				'wp-i18n',
110
-				'kirki-control-base',
111
-			],
112
-			time(),
113
-			false
114
-		);
115
-
116
-		// Enqueue the style.
117
-		wp_enqueue_style( 'kirki-control-select-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
118
-
119
-	}
120
-
121
-	/**
122
-	 * Get the URL for the control folder.
123
-	 *
124
-	 * This is a static method because there are more controls in the Kirki framework
125
-	 * that use colorpickers, and they all need to enqueue the same assets.
126
-	 *
127
-	 * @static
128
-	 * @access public
129
-	 * @since 1.0.6
130
-	 * @return string
131
-	 */
132
-	public static function get_control_path_url() {
133
-
134
-		return URL::get_from_path( dirname( __DIR__ ) );
135
-
136
-	}
137
-
138
-	/**
139
-	 * Refresh the parameters passed to the JavaScript via JSON.
140
-	 *
141
-	 * @see WP_Customize_Control::to_json()
142
-	 *
143
-	 * @access public
144
-	 * @since 1.0
145
-	 * @return void
146
-	 */
147
-	public function to_json() {
148
-
149
-		parent::to_json();
150
-
151
-		if ( isset( $this->json['label'] ) ) {
152
-			$this->json['label'] = html_entity_decode( $this->json['label'] );
153
-		}
154
-
155
-		if ( isset( $this->json['description'] ) ) {
156
-			$this->json['description'] = html_entity_decode( $this->json['description'] );
157
-		}
158
-
159
-		// @link https://react-select.com/props
160
-		$this->json['isClearable'] = $this->clearable;
161
-		$this->json['isMulti']     = $this->multiple;
162
-		$this->json['placeholder'] = ( $this->placeholder ) ? $this->placeholder : esc_html__( 'Select...', 'kirki' );
163
-
164
-		// Will be a custom implementation, couldn't find an official prop to set this in react-select.
165
-		$this->json['maxSelectionNumber'] = $this->max_selection_number;
166
-
167
-		$this->json['messages'] = [
168
-			// translators: %s is the limit of selection number.
169
-			'maxLimitReached' => sprintf( esc_html__( 'You can only select %s items', 'kirki' ), $this->max_selection_number ),
170
-		];
171
-
172
-	}
23
+    /**
24
+     * The control type.
25
+     *
26
+     * @access public
27
+     * @since 1.0
28
+     * @var string
29
+     */
30
+    public $type = 'kirki-react-select';
31
+
32
+    /**
33
+     * Placeholder text.
34
+     *
35
+     * @access public
36
+     * @since 1.0
37
+     * @var string|false
38
+     */
39
+    public $placeholder = false;
40
+
41
+    /**
42
+     * Whether the select should be clearable or not.
43
+     *
44
+     * @since 1.0
45
+     * @var bool
46
+     */
47
+    public $clearable = false;
48
+
49
+    /**
50
+     * Whether this is a multi-select or not.
51
+     *
52
+     * *Backwards compatibility note:
53
+     *
54
+     * Previously (when Kirki used Select2), $multiple is used to:
55
+     * - Determine whether the select is multiple or not.
56
+     * - Determine the maximum number of selection.
57
+     *
58
+     * Start from Kirki 4 (when Kirki uses react-select),
59
+     * $multiple is used to determine whether the select is multiple or not.
60
+     * The maximum selection number is now set in $max_selection.
61
+     *
62
+     * @access public
63
+     * @since 1.0
64
+     * @var bool
65
+     */
66
+    public $multiple = false;
67
+
68
+    /**
69
+     * The maximum selection length for multiple selection.
70
+     *
71
+     * @access public
72
+     * @since 1.1
73
+     * @var bool
74
+     */
75
+    public $max_selection_number = 999;
76
+
77
+    /**
78
+     * The version. Used in scripts & styles for cache-busting.
79
+     *
80
+     * @static
81
+     * @access public
82
+     * @since 1.0
83
+     * @var string
84
+     */
85
+    public static $control_ver = '1.1.5';
86
+
87
+    /**
88
+     * Enqueue control related scripts/styles.
89
+     *
90
+     * @access public
91
+     * @since 1.0
92
+     * @return void
93
+     */
94
+    public function enqueue() {
95
+
96
+        parent::enqueue();
97
+
98
+        // Enqueue the script.
99
+        wp_enqueue_script(
100
+            'kirki-control-select',
101
+            URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ),
102
+            [
103
+                'customize-controls',
104
+                'customize-base',
105
+                'wp-element',
106
+                'wp-compose',
107
+                'wp-components',
108
+                'jquery',
109
+                'wp-i18n',
110
+                'kirki-control-base',
111
+            ],
112
+            time(),
113
+            false
114
+        );
115
+
116
+        // Enqueue the style.
117
+        wp_enqueue_style( 'kirki-control-select-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
118
+
119
+    }
120
+
121
+    /**
122
+     * Get the URL for the control folder.
123
+     *
124
+     * This is a static method because there are more controls in the Kirki framework
125
+     * that use colorpickers, and they all need to enqueue the same assets.
126
+     *
127
+     * @static
128
+     * @access public
129
+     * @since 1.0.6
130
+     * @return string
131
+     */
132
+    public static function get_control_path_url() {
133
+
134
+        return URL::get_from_path( dirname( __DIR__ ) );
135
+
136
+    }
137
+
138
+    /**
139
+     * Refresh the parameters passed to the JavaScript via JSON.
140
+     *
141
+     * @see WP_Customize_Control::to_json()
142
+     *
143
+     * @access public
144
+     * @since 1.0
145
+     * @return void
146
+     */
147
+    public function to_json() {
148
+
149
+        parent::to_json();
150
+
151
+        if ( isset( $this->json['label'] ) ) {
152
+            $this->json['label'] = html_entity_decode( $this->json['label'] );
153
+        }
154
+
155
+        if ( isset( $this->json['description'] ) ) {
156
+            $this->json['description'] = html_entity_decode( $this->json['description'] );
157
+        }
158
+
159
+        // @link https://react-select.com/props
160
+        $this->json['isClearable'] = $this->clearable;
161
+        $this->json['isMulti']     = $this->multiple;
162
+        $this->json['placeholder'] = ( $this->placeholder ) ? $this->placeholder : esc_html__( 'Select...', 'kirki' );
163
+
164
+        // Will be a custom implementation, couldn't find an official prop to set this in react-select.
165
+        $this->json['maxSelectionNumber'] = $this->max_selection_number;
166
+
167
+        $this->json['messages'] = [
168
+            // translators: %s is the limit of selection number.
169
+            'maxLimitReached' => sprintf( esc_html__( 'You can only select %s items', 'kirki' ), $this->max_selection_number ),
170
+        ];
171
+
172
+    }
173 173
 
174 174
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Field/Checkbox_Toggle.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -15,41 +15,41 @@
 block discarded – undo
15 15
  */
16 16
 class Checkbox_Toggle extends Checkbox {
17 17
 
18
-	/**
19
-	 * The field type.
20
-	 *
21
-	 * @access public
22
-	 * @since 1.0
23
-	 * @var string
24
-	 */
25
-	public $type = 'kirki-toggle';
26
-
27
-	/**
28
-	 * The control class-name.
29
-	 *
30
-	 * @access protected
31
-	 * @since 0.1
32
-	 * @var string
33
-	 */
34
-	protected $control_class = '\Kirki\Control\Checkbox_Toggle';
35
-
36
-	/**
37
-	 * Filter arguments before creating the control.
38
-	 *
39
-	 * @access public
40
-	 * @since 0.1
41
-	 * @param array                $args         The field arguments.
42
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
43
-	 * @return array
44
-	 */
45
-	public function filter_control_args( $args, $wp_customize ) {
46
-
47
-		if ( $args['settings'] === $this->args['settings'] ) {
48
-			$args         = parent::filter_control_args( $args, $wp_customize );
49
-			$args['type'] = 'kirki-toggle';
50
-		}
51
-
52
-		return $args;
53
-
54
-	}
18
+    /**
19
+     * The field type.
20
+     *
21
+     * @access public
22
+     * @since 1.0
23
+     * @var string
24
+     */
25
+    public $type = 'kirki-toggle';
26
+
27
+    /**
28
+     * The control class-name.
29
+     *
30
+     * @access protected
31
+     * @since 0.1
32
+     * @var string
33
+     */
34
+    protected $control_class = '\Kirki\Control\Checkbox_Toggle';
35
+
36
+    /**
37
+     * Filter arguments before creating the control.
38
+     *
39
+     * @access public
40
+     * @since 0.1
41
+     * @param array                $args         The field arguments.
42
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
43
+     * @return array
44
+     */
45
+    public function filter_control_args( $args, $wp_customize ) {
46
+
47
+        if ( $args['settings'] === $this->args['settings'] ) {
48
+            $args         = parent::filter_control_args( $args, $wp_customize );
49
+            $args['type'] = 'kirki-toggle';
50
+        }
51
+
52
+        return $args;
53
+
54
+    }
55 55
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Field/Checkbox_Switch.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -17,41 +17,41 @@
 block discarded – undo
17 17
  */
18 18
 class Checkbox_Switch extends Checkbox {
19 19
 
20
-	/**
21
-	 * The field type.
22
-	 *
23
-	 * @access public
24
-	 * @since 1.0
25
-	 * @var string
26
-	 */
27
-	public $type = 'kirki-switch';
28
-
29
-	/**
30
-	 * The control class-name.
31
-	 *
32
-	 * @access protected
33
-	 * @since 0.1
34
-	 * @var string
35
-	 */
36
-	protected $control_class = '\Kirki\Control\Checkbox_Switch';
37
-
38
-	/**
39
-	 * Filter arguments before creating the control.
40
-	 *
41
-	 * @access public
42
-	 * @since 0.1
43
-	 * @param array                $args         The field arguments.
44
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
45
-	 * @return array
46
-	 */
47
-	public function filter_control_args( $args, $wp_customize ) {
48
-
49
-		if ( $args['settings'] === $this->args['settings'] ) {
50
-			$args         = parent::filter_control_args( $args, $wp_customize );
51
-			$args['type'] = 'kirki-switch';
52
-		}
53
-
54
-		return $args;
55
-
56
-	}
20
+    /**
21
+     * The field type.
22
+     *
23
+     * @access public
24
+     * @since 1.0
25
+     * @var string
26
+     */
27
+    public $type = 'kirki-switch';
28
+
29
+    /**
30
+     * The control class-name.
31
+     *
32
+     * @access protected
33
+     * @since 0.1
34
+     * @var string
35
+     */
36
+    protected $control_class = '\Kirki\Control\Checkbox_Switch';
37
+
38
+    /**
39
+     * Filter arguments before creating the control.
40
+     *
41
+     * @access public
42
+     * @since 0.1
43
+     * @param array                $args         The field arguments.
44
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
45
+     * @return array
46
+     */
47
+    public function filter_control_args( $args, $wp_customize ) {
48
+
49
+        if ( $args['settings'] === $this->args['settings'] ) {
50
+            $args         = parent::filter_control_args( $args, $wp_customize );
51
+            $args['type'] = 'kirki-switch';
52
+        }
53
+
54
+        return $args;
55
+
56
+    }
57 57
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Field/Checkbox.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -19,81 +19,81 @@
 block discarded – undo
19 19
  */
20 20
 class Checkbox extends Field {
21 21
 
22
-	/**
23
-	 * The field type.
24
-	 *
25
-	 * @access public
26
-	 * @since 1.0
27
-	 * @var string
28
-	 */
29
-	public $type = 'kirki-checkbox';
30
-
31
-	/**
32
-	 * The control class-name.
33
-	 *
34
-	 * @access protected
35
-	 * @since 0.1
36
-	 * @var string
37
-	 */
38
-	protected $control_class = '\Kirki\Control\Checkbox';
39
-
40
-	/**
41
-	 * Whether we should register the control class for JS-templating or not.
42
-	 *
43
-	 * @access protected
44
-	 * @since 0.1
45
-	 * @var bool
46
-	 */
47
-	protected $control_has_js_template = true;
48
-
49
-	/**
50
-	 * Filter arguments before creating the setting.
51
-	 *
52
-	 * @access public
53
-	 * @since 0.1
54
-	 * @param array                $args         The field arguments.
55
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
56
-	 * @return array
57
-	 */
58
-	public function filter_setting_args( $args, $wp_customize ) {
59
-
60
-		if ( $args['settings'] === $this->args['settings'] ) {
61
-			$args = parent::filter_setting_args( $args, $wp_customize );
62
-
63
-			// Set the sanitize-callback if none is defined.
64
-			if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
65
-				$args['sanitize_callback'] = function( $value ) {
66
-					return ( '0' === $value || 'false' === $value ) ? false : (bool) $value;
67
-				};
68
-			}
69
-
70
-			$args['default'] = isset( $args['default'] ) ? $args['default'] : false;
71
-
72
-			// Make sure the default is formatted as boolean.
73
-			$args['default'] = (bool) ( 1 === $args['default'] || '1' === $args['default'] || true === $args['default'] || 'true' === $args['default'] || 'on' === $args['default'] );
74
-		}
75
-
76
-		return $args;
77
-
78
-	}
79
-
80
-	/**
81
-	 * Filter arguments before creating the control.
82
-	 *
83
-	 * @access public
84
-	 * @since 0.1
85
-	 * @param array                $args         The field arguments.
86
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
87
-	 * @return array
88
-	 */
89
-	public function filter_control_args( $args, $wp_customize ) {
90
-
91
-		if ( $args['settings'] === $this->args['settings'] ) {
92
-			$args         = parent::filter_control_args( $args, $wp_customize );
93
-			$args['type'] = 'kirki-checkbox';
94
-		}
95
-
96
-		return $args;
97
-
98
-	}
22
+    /**
23
+     * The field type.
24
+     *
25
+     * @access public
26
+     * @since 1.0
27
+     * @var string
28
+     */
29
+    public $type = 'kirki-checkbox';
30
+
31
+    /**
32
+     * The control class-name.
33
+     *
34
+     * @access protected
35
+     * @since 0.1
36
+     * @var string
37
+     */
38
+    protected $control_class = '\Kirki\Control\Checkbox';
39
+
40
+    /**
41
+     * Whether we should register the control class for JS-templating or not.
42
+     *
43
+     * @access protected
44
+     * @since 0.1
45
+     * @var bool
46
+     */
47
+    protected $control_has_js_template = true;
48
+
49
+    /**
50
+     * Filter arguments before creating the setting.
51
+     *
52
+     * @access public
53
+     * @since 0.1
54
+     * @param array                $args         The field arguments.
55
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
56
+     * @return array
57
+     */
58
+    public function filter_setting_args( $args, $wp_customize ) {
59
+
60
+        if ( $args['settings'] === $this->args['settings'] ) {
61
+            $args = parent::filter_setting_args( $args, $wp_customize );
62
+
63
+            // Set the sanitize-callback if none is defined.
64
+            if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
65
+                $args['sanitize_callback'] = function( $value ) {
66
+                    return ( '0' === $value || 'false' === $value ) ? false : (bool) $value;
67
+                };
68
+            }
69
+
70
+            $args['default'] = isset( $args['default'] ) ? $args['default'] : false;
71
+
72
+            // Make sure the default is formatted as boolean.
73
+            $args['default'] = (bool) ( 1 === $args['default'] || '1' === $args['default'] || true === $args['default'] || 'true' === $args['default'] || 'on' === $args['default'] );
74
+        }
75
+
76
+        return $args;
77
+
78
+    }
79
+
80
+    /**
81
+     * Filter arguments before creating the control.
82
+     *
83
+     * @access public
84
+     * @since 0.1
85
+     * @param array                $args         The field arguments.
86
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
87
+     * @return array
88
+     */
89
+    public function filter_control_args( $args, $wp_customize ) {
90
+
91
+        if ( $args['settings'] === $this->args['settings'] ) {
92
+            $args         = parent::filter_control_args( $args, $wp_customize );
93
+            $args['type'] = 'kirki-checkbox';
94
+        }
95
+
96
+        return $args;
97
+
98
+    }
99 99
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Control/Checkbox_Toggle.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 // Exit if accessed directly.
14 14
 if ( ! defined( 'ABSPATH' ) ) {
15
-	exit;
15
+    exit;
16 16
 }
17 17
 
18 18
 /**
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Checkbox_Toggle extends Checkbox_Switch {
24 24
 
25
-	/**
26
-	 * The control type.
27
-	 *
28
-	 * @access public
29
-	 * @since 1.0
30
-	 * @var string
31
-	 */
32
-	public $type = 'kirki-toggle';
25
+    /**
26
+     * The control type.
27
+     *
28
+     * @access public
29
+     * @since 1.0
30
+     * @var string
31
+     */
32
+    public $type = 'kirki-toggle';
33 33
 
34 34
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Control/Checkbox_Switch.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // Exit if accessed directly.
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 /**
@@ -25,77 +25,77 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Checkbox_Switch extends Base {
27 27
 
28
-	/**
29
-	 * The control type.
30
-	 *
31
-	 * @access public
32
-	 * @since 1.0
33
-	 * @var string
34
-	 */
35
-	public $type = 'kirki-switch';
36
-
37
-	/**
38
-	 * The control version.
39
-	 *
40
-	 * @static
41
-	 * @access public
42
-	 * @since 1.0
43
-	 * @var string
44
-	 */
45
-	public static $control_ver = '1.0.3';
46
-
47
-	/**
48
-	 * Enqueue control related scripts/styles.
49
-	 *
50
-	 * @access public
51
-	 * @since 1.0
52
-	 * @return void
53
-	 */
54
-	public function enqueue() {
55
-
56
-		parent::enqueue();
57
-
58
-		// Enqueue the script.
59
-		wp_enqueue_script( 'kirki-control-checkbox', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
60
-
61
-		// Enqueue the style.
62
-		wp_enqueue_style( 'kirki-control-checkbox-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
63
-
64
-	}
65
-
66
-	/**
67
-	 * Refresh the parameters passed to the JavaScript via JSON.
68
-	 *
69
-	 * @since 3.4.0
70
-	 */
71
-	public function to_json() {
72
-
73
-		// Get the basics from the parent class.
74
-		parent::to_json();
75
-
76
-		$this->json['checkboxType'] = str_ireplace( 'kirki-', '', $this->type );
77
-
78
-		$this->json['defaultChoices'] = [
79
-			'on'  => __( 'On', 'kirki' ),
80
-			'off' => __( 'Off', 'kirki' ),
81
-		];
82
-
83
-	}
84
-
85
-	/**
86
-	 * An Underscore (JS) template for this control's content (but not its container).
87
-	 *
88
-	 * Class variables for this control class are available in the `data` JS object;
89
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
90
-	 *
91
-	 * @see WP_Customize_Control::print_template()
92
-	 *
93
-	 * @access protected
94
-	 * @since 1.0
95
-	 * @return void
96
-	 */
97
-	protected function content_template() {
98
-		?>
28
+    /**
29
+     * The control type.
30
+     *
31
+     * @access public
32
+     * @since 1.0
33
+     * @var string
34
+     */
35
+    public $type = 'kirki-switch';
36
+
37
+    /**
38
+     * The control version.
39
+     *
40
+     * @static
41
+     * @access public
42
+     * @since 1.0
43
+     * @var string
44
+     */
45
+    public static $control_ver = '1.0.3';
46
+
47
+    /**
48
+     * Enqueue control related scripts/styles.
49
+     *
50
+     * @access public
51
+     * @since 1.0
52
+     * @return void
53
+     */
54
+    public function enqueue() {
55
+
56
+        parent::enqueue();
57
+
58
+        // Enqueue the script.
59
+        wp_enqueue_script( 'kirki-control-checkbox', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
60
+
61
+        // Enqueue the style.
62
+        wp_enqueue_style( 'kirki-control-checkbox-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
63
+
64
+    }
65
+
66
+    /**
67
+     * Refresh the parameters passed to the JavaScript via JSON.
68
+     *
69
+     * @since 3.4.0
70
+     */
71
+    public function to_json() {
72
+
73
+        // Get the basics from the parent class.
74
+        parent::to_json();
75
+
76
+        $this->json['checkboxType'] = str_ireplace( 'kirki-', '', $this->type );
77
+
78
+        $this->json['defaultChoices'] = [
79
+            'on'  => __( 'On', 'kirki' ),
80
+            'off' => __( 'Off', 'kirki' ),
81
+        ];
82
+
83
+    }
84
+
85
+    /**
86
+     * An Underscore (JS) template for this control's content (but not its container).
87
+     *
88
+     * Class variables for this control class are available in the `data` JS object;
89
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
90
+     *
91
+     * @see WP_Customize_Control::print_template()
92
+     *
93
+     * @access protected
94
+     * @since 1.0
95
+     * @return void
96
+     */
97
+    protected function content_template() {
98
+        ?>
99 99
 
100 100
 		<div class="kirki-{{ data.checkboxType }}-control kirki-{{ data.checkboxType }}">
101 101
 			<# if ( data.label || data.description ) { #>
@@ -130,5 +130,5 @@  discard block
 block discarded – undo
130 130
 		</div>
131 131
 
132 132
 		<?php
133
-	}
133
+    }
134 134
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-checkbox/src/Control/Checkbox.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -23,56 +23,56 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Checkbox extends Base {
25 25
 
26
-	/**
27
-	 * The control type.
28
-	 *
29
-	 * @access public
30
-	 * @since 1.0
31
-	 * @var string
32
-	 */
33
-	public $type = 'kirki-checkbox';
26
+    /**
27
+     * The control type.
28
+     *
29
+     * @access public
30
+     * @since 1.0
31
+     * @var string
32
+     */
33
+    public $type = 'kirki-checkbox';
34 34
 
35
-	/**
36
-	 * The control version.
37
-	 *
38
-	 * @static
39
-	 * @access public
40
-	 * @since 1.0
41
-	 * @var string
42
-	 */
43
-	public static $control_ver = '1.0.3';
35
+    /**
36
+     * The control version.
37
+     *
38
+     * @static
39
+     * @access public
40
+     * @since 1.0
41
+     * @var string
42
+     */
43
+    public static $control_ver = '1.0.3';
44 44
 
45
-	/**
46
-	 * Enqueue control related scripts/styles.
47
-	 *
48
-	 * @access public
49
-	 * @since 1.0
50
-	 * @return void
51
-	 */
52
-	public function enqueue() {
53
-		parent::enqueue();
45
+    /**
46
+     * Enqueue control related scripts/styles.
47
+     *
48
+     * @access public
49
+     * @since 1.0
50
+     * @return void
51
+     */
52
+    public function enqueue() {
53
+        parent::enqueue();
54 54
 
55
-		// Enqueue the script.
56
-		wp_enqueue_script( 'kirki-control-checkbox', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
55
+        // Enqueue the script.
56
+        wp_enqueue_script( 'kirki-control-checkbox', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
57 57
 
58
-		// Enqueue the style.
59
-		wp_enqueue_style( 'kirki-control-checkbox-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
60
-	}
58
+        // Enqueue the style.
59
+        wp_enqueue_style( 'kirki-control-checkbox-style', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver );
60
+    }
61 61
 
62
-	/**
63
-	 * An Underscore (JS) template for this control's content (but not its container).
64
-	 *
65
-	 * Class variables for this control class are available in the `data` JS object;
66
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
67
-	 *
68
-	 * @see WP_Customize_Control::print_template()
69
-	 *
70
-	 * @access protected
71
-	 * @since 1.0
72
-	 * @return void
73
-	 */
74
-	protected function content_template() {
75
-		?>
62
+    /**
63
+     * An Underscore (JS) template for this control's content (but not its container).
64
+     *
65
+     * Class variables for this control class are available in the `data` JS object;
66
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
67
+     *
68
+     * @see WP_Customize_Control::print_template()
69
+     *
70
+     * @access protected
71
+     * @since 1.0
72
+     * @return void
73
+     */
74
+    protected function content_template() {
75
+        ?>
76 76
 		<input
77 77
 			id="_customize-input-{{ data.id }}"
78 78
 			type="checkbox"
@@ -86,5 +86,5 @@  discard block
 block discarded – undo
86 86
 			<span id="_customize-description-{{ data.id }}" class="description customize-control-description">{{{ data.description }}}</span>
87 87
 		<# } #>
88 88
 		<?php
89
-	}
89
+    }
90 90
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/field-dimensions/src/Dimensions.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -21,247 +21,247 @@
 block discarded – undo
21 21
  */
22 22
 class Dimensions extends Field {
23 23
 
24
-	/**
25
-	 * The field type.
26
-	 *
27
-	 * @access public
28
-	 * @since 1.0
29
-	 * @var string
30
-	 */
31
-	public $type = 'kirki-dimensions';
32
-
33
-	/**
34
-	 * Extra logic for the field.
35
-	 *
36
-	 * Adds all sub-fields.
37
-	 *
38
-	 * @access public
39
-	 * @param array $args The arguments of the field.
40
-	 */
41
-	public function init( $args = array() ) {
42
-
43
-		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
44
-		add_action( 'customize_preview_init', array( $this, 'enqueue_customize_preview_scripts' ) );
45
-		add_filter( 'kirki_output_control_classnames', array( $this, 'output_control_classnames' ) );
46
-
47
-		$args['required'] = isset( $args['required'] ) ? (array) $args['required'] : array();
48
-
49
-		$labels = array(
50
-			'left-top'       => esc_html__( 'Left Top', 'kirki' ),
51
-			'left-center'    => esc_html__( 'Left Center', 'kirki' ),
52
-			'left-bottom'    => esc_html__( 'Left Bottom', 'kirki' ),
53
-			'right-top'      => esc_html__( 'Right Top', 'kirki' ),
54
-			'right-center'   => esc_html__( 'Right Center', 'kirki' ),
55
-			'right-bottom'   => esc_html__( 'Right Bottom', 'kirki' ),
56
-			'center-top'     => esc_html__( 'Center Top', 'kirki' ),
57
-			'center-center'  => esc_html__( 'Center Center', 'kirki' ),
58
-			'center-bottom'  => esc_html__( 'Center Bottom', 'kirki' ),
59
-			'font-size'      => esc_html__( 'Font Size', 'kirki' ),
60
-			'font-weight'    => esc_html__( 'Font Weight', 'kirki' ),
61
-			'line-height'    => esc_html__( 'Line Height', 'kirki' ),
62
-			'font-style'     => esc_html__( 'Font Style', 'kirki' ),
63
-			'letter-spacing' => esc_html__( 'Letter Spacing', 'kirki' ),
64
-			'word-spacing'   => esc_html__( 'Word Spacing', 'kirki' ),
65
-			'top'            => esc_html__( 'Top', 'kirki' ),
66
-			'bottom'         => esc_html__( 'Bottom', 'kirki' ),
67
-			'left'           => esc_html__( 'Left', 'kirki' ),
68
-			'right'          => esc_html__( 'Right', 'kirki' ),
69
-			'center'         => esc_html__( 'Center', 'kirki' ),
70
-			'size'           => esc_html__( 'Size', 'kirki' ),
71
-			'spacing'        => esc_html__( 'Spacing', 'kirki' ),
72
-			'width'          => esc_html__( 'Width', 'kirki' ),
73
-			'height'         => esc_html__( 'Height', 'kirki' ),
74
-			'invalid-value'  => esc_html__( 'Invalid Value', 'kirki' ),
75
-		);
76
-
77
-		/**
78
-		 * Add a hidden field, the label & description.
79
-		 */
80
-		new \Kirki\Field\Generic(
81
-			wp_parse_args(
82
-				array(
83
-					'type'              => 'kirki-generic',
84
-					'default'           => '',
85
-					'wrapper_opts'      => array(
86
-						'gap' => 'small',
87
-					),
88
-					'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : array( __CLASS__, 'sanitize' ),
89
-					'choices'           => array(
90
-						'type'        => 'hidden',
91
-						'parent_type' => 'kirki-dimensions',
92
-					),
93
-				),
94
-				$args
95
-			)
96
-		);
97
-
98
-		$args['choices']           = isset( $args['choices'] ) ? $args['choices'] : array();
99
-		$args['choices']['labels'] = isset( $args['choices']['labels'] ) ? $args['choices']['labels'] : array();
100
-
101
-		if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
102
-			$args['transport'] = 'postMessage';
103
-		}
104
-
105
-		$total_items = count( $args['default'] );
106
-		$item_count  = 0;
107
-
108
-		$width = 100;
109
-
110
-		$break_indexes = array();
111
-
112
-		// The 'kirki-group-break' only supports 12 group items inside a group.
113
-		if ( 2 === $total_items ) {
114
-			$width = 50;
115
-		} elseif ( 3 === $total_items ) {
116
-			$width = 33;
117
-		} elseif ( 4 === $total_items ) {
118
-			$width = 25;
119
-		} elseif ( 5 === $total_items ) {
120
-			array_push( $break_indexes, 3 );
121
-			$width = 33;
122
-		} elseif ( 6 === $total_items ) {
123
-			array_push( $break_indexes, 3 );
124
-			$width = 33;
125
-		} elseif ( 7 === $total_items || 8 === $total_items ) {
126
-			array_push( $break_indexes, 4 );
127
-			$width = 25;
128
-		} elseif ( 9 === $total_items ) {
129
-			array_push( $break_indexes, 3, 6 );
130
-			$width = 33;
131
-		} elseif ( $total_items > 9 ) {
132
-			array_push( $break_indexes, 4, 8 );
133
-			$width = 25;
134
-		}
135
-
136
-		foreach ( $args['default'] as $choice => $default ) {
137
-			$item_count++;
138
-
139
-			$label = $choice;
140
-			$label = isset( $labels[ $choice ] ) ? $labels[ $choice ] : $label;
141
-			$label = isset( $args['choices']['labels'][ $choice ] ) ? $args['choices']['labels'][ $choice ] : $label;
142
-
143
-			$wrapper_attrs = array(
144
-				'data-kirki-parent-control-type'    => 'kirki-dimensions',
145
-				'data-kirki-parent-control-setting' => $args['settings'],
146
-				'class'                             => '{default_class} kirki-group-item kirki-w' . $width,
147
-			);
148
-
149
-			if ( $item_count === 1 ) {
150
-				$wrapper_attrs['class'] .= ' kirki-group-start';
151
-			}
152
-
153
-			if ( in_array( $item_count, $break_indexes, true ) ) {
154
-				$wrapper_attrs['class'] .= ' kirki-group-break';
155
-			}
156
-
157
-			if ( $item_count === $total_items ) {
158
-				$wrapper_attrs['class'] .= ' kirki-group-end';
159
-			}
160
-
161
-			new \Kirki\Field\Dimension(
162
-				wp_parse_args(
163
-					array(
164
-						'type'           => 'kirki-dimension',
165
-						'settings'       => $args['settings'] . '[' . $choice . ']',
166
-						'parent_setting' => $args['settings'],
167
-						'label'          => $label,
168
-						'default'        => $default,
169
-						'wrapper_attrs'  => $wrapper_attrs,
170
-						'choices'        => array(
171
-							'label_position' => 'bottom',
172
-						),
173
-						'js_vars'        => array(),
174
-						'css_vars'       => array(),
175
-						'output'         => array(),
176
-					),
177
-					$args
178
-				)
179
-			);
180
-		}
181
-
182
-	}
183
-
184
-	/**
185
-	 * Sanitizes dimension controls.
186
-	 *
187
-	 * @static
188
-	 * @access public
189
-	 * @since 1.0
190
-	 * @param array $value The value.
191
-	 * @return array
192
-	 */
193
-	public static function sanitize( $value ) {
194
-
195
-		if ( ! is_array( $value ) ) {
196
-			return array();
197
-		}
198
-
199
-		foreach ( $value as $key => $val ) {
200
-			$value[ $key ] = sanitize_text_field( $val );
201
-		}
202
-
203
-		return $value;
204
-
205
-	}
206
-
207
-	/**
208
-	 * Override parent method. No need to register any setting.
209
-	 *
210
-	 * @access public
211
-	 * @since 0.1
212
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
213
-	 * @return void
214
-	 */
215
-	public function add_setting( $wp_customize ) {}
216
-
217
-	/**
218
-	 * Override the parent method. No need for a control.
219
-	 *
220
-	 * @access public
221
-	 * @since 0.1
222
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
223
-	 * @return void
224
-	 */
225
-	public function add_control( $wp_customize ) {}
226
-
227
-	/**
228
-	 * Enqueue scripts & styles.
229
-	 *
230
-	 * @access public
231
-	 * @since 1.0
232
-	 * @return void
233
-	 */
234
-	public function enqueue_scripts() {
235
-
236
-		wp_enqueue_style( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) . '/dist/control.css' ), array(), '1.0' );
237
-
238
-	}
239
-
240
-	/**
241
-	 * Enqueue scripts & styles on customize_preview_init.
242
-	 *
243
-	 * @access public
244
-	 * @since 1.0
245
-	 * @return void
246
-	 */
247
-	public function enqueue_customize_preview_scripts() {
248
-
249
-		wp_enqueue_script( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) ) . '/dist/preview.js', array( 'wp-hooks' ), '1.0', true );
250
-
251
-	}
252
-
253
-	/**
254
-	 * Adds a custom output class for typography fields.
255
-	 *
256
-	 * @access public
257
-	 * @since 1.0
258
-	 * @param array $classnames The array of classnames.
259
-	 * @return array
260
-	 */
261
-	public function output_control_classnames( $classnames ) {
262
-
263
-		$classnames['kirki-dimensions'] = '\Kirki\Field\CSS\Dimensions';
264
-		return $classnames;
265
-
266
-	}
24
+    /**
25
+     * The field type.
26
+     *
27
+     * @access public
28
+     * @since 1.0
29
+     * @var string
30
+     */
31
+    public $type = 'kirki-dimensions';
32
+
33
+    /**
34
+     * Extra logic for the field.
35
+     *
36
+     * Adds all sub-fields.
37
+     *
38
+     * @access public
39
+     * @param array $args The arguments of the field.
40
+     */
41
+    public function init( $args = array() ) {
42
+
43
+        add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
44
+        add_action( 'customize_preview_init', array( $this, 'enqueue_customize_preview_scripts' ) );
45
+        add_filter( 'kirki_output_control_classnames', array( $this, 'output_control_classnames' ) );
46
+
47
+        $args['required'] = isset( $args['required'] ) ? (array) $args['required'] : array();
48
+
49
+        $labels = array(
50
+            'left-top'       => esc_html__( 'Left Top', 'kirki' ),
51
+            'left-center'    => esc_html__( 'Left Center', 'kirki' ),
52
+            'left-bottom'    => esc_html__( 'Left Bottom', 'kirki' ),
53
+            'right-top'      => esc_html__( 'Right Top', 'kirki' ),
54
+            'right-center'   => esc_html__( 'Right Center', 'kirki' ),
55
+            'right-bottom'   => esc_html__( 'Right Bottom', 'kirki' ),
56
+            'center-top'     => esc_html__( 'Center Top', 'kirki' ),
57
+            'center-center'  => esc_html__( 'Center Center', 'kirki' ),
58
+            'center-bottom'  => esc_html__( 'Center Bottom', 'kirki' ),
59
+            'font-size'      => esc_html__( 'Font Size', 'kirki' ),
60
+            'font-weight'    => esc_html__( 'Font Weight', 'kirki' ),
61
+            'line-height'    => esc_html__( 'Line Height', 'kirki' ),
62
+            'font-style'     => esc_html__( 'Font Style', 'kirki' ),
63
+            'letter-spacing' => esc_html__( 'Letter Spacing', 'kirki' ),
64
+            'word-spacing'   => esc_html__( 'Word Spacing', 'kirki' ),
65
+            'top'            => esc_html__( 'Top', 'kirki' ),
66
+            'bottom'         => esc_html__( 'Bottom', 'kirki' ),
67
+            'left'           => esc_html__( 'Left', 'kirki' ),
68
+            'right'          => esc_html__( 'Right', 'kirki' ),
69
+            'center'         => esc_html__( 'Center', 'kirki' ),
70
+            'size'           => esc_html__( 'Size', 'kirki' ),
71
+            'spacing'        => esc_html__( 'Spacing', 'kirki' ),
72
+            'width'          => esc_html__( 'Width', 'kirki' ),
73
+            'height'         => esc_html__( 'Height', 'kirki' ),
74
+            'invalid-value'  => esc_html__( 'Invalid Value', 'kirki' ),
75
+        );
76
+
77
+        /**
78
+         * Add a hidden field, the label & description.
79
+         */
80
+        new \Kirki\Field\Generic(
81
+            wp_parse_args(
82
+                array(
83
+                    'type'              => 'kirki-generic',
84
+                    'default'           => '',
85
+                    'wrapper_opts'      => array(
86
+                        'gap' => 'small',
87
+                    ),
88
+                    'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : array( __CLASS__, 'sanitize' ),
89
+                    'choices'           => array(
90
+                        'type'        => 'hidden',
91
+                        'parent_type' => 'kirki-dimensions',
92
+                    ),
93
+                ),
94
+                $args
95
+            )
96
+        );
97
+
98
+        $args['choices']           = isset( $args['choices'] ) ? $args['choices'] : array();
99
+        $args['choices']['labels'] = isset( $args['choices']['labels'] ) ? $args['choices']['labels'] : array();
100
+
101
+        if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
102
+            $args['transport'] = 'postMessage';
103
+        }
104
+
105
+        $total_items = count( $args['default'] );
106
+        $item_count  = 0;
107
+
108
+        $width = 100;
109
+
110
+        $break_indexes = array();
111
+
112
+        // The 'kirki-group-break' only supports 12 group items inside a group.
113
+        if ( 2 === $total_items ) {
114
+            $width = 50;
115
+        } elseif ( 3 === $total_items ) {
116
+            $width = 33;
117
+        } elseif ( 4 === $total_items ) {
118
+            $width = 25;
119
+        } elseif ( 5 === $total_items ) {
120
+            array_push( $break_indexes, 3 );
121
+            $width = 33;
122
+        } elseif ( 6 === $total_items ) {
123
+            array_push( $break_indexes, 3 );
124
+            $width = 33;
125
+        } elseif ( 7 === $total_items || 8 === $total_items ) {
126
+            array_push( $break_indexes, 4 );
127
+            $width = 25;
128
+        } elseif ( 9 === $total_items ) {
129
+            array_push( $break_indexes, 3, 6 );
130
+            $width = 33;
131
+        } elseif ( $total_items > 9 ) {
132
+            array_push( $break_indexes, 4, 8 );
133
+            $width = 25;
134
+        }
135
+
136
+        foreach ( $args['default'] as $choice => $default ) {
137
+            $item_count++;
138
+
139
+            $label = $choice;
140
+            $label = isset( $labels[ $choice ] ) ? $labels[ $choice ] : $label;
141
+            $label = isset( $args['choices']['labels'][ $choice ] ) ? $args['choices']['labels'][ $choice ] : $label;
142
+
143
+            $wrapper_attrs = array(
144
+                'data-kirki-parent-control-type'    => 'kirki-dimensions',
145
+                'data-kirki-parent-control-setting' => $args['settings'],
146
+                'class'                             => '{default_class} kirki-group-item kirki-w' . $width,
147
+            );
148
+
149
+            if ( $item_count === 1 ) {
150
+                $wrapper_attrs['class'] .= ' kirki-group-start';
151
+            }
152
+
153
+            if ( in_array( $item_count, $break_indexes, true ) ) {
154
+                $wrapper_attrs['class'] .= ' kirki-group-break';
155
+            }
156
+
157
+            if ( $item_count === $total_items ) {
158
+                $wrapper_attrs['class'] .= ' kirki-group-end';
159
+            }
160
+
161
+            new \Kirki\Field\Dimension(
162
+                wp_parse_args(
163
+                    array(
164
+                        'type'           => 'kirki-dimension',
165
+                        'settings'       => $args['settings'] . '[' . $choice . ']',
166
+                        'parent_setting' => $args['settings'],
167
+                        'label'          => $label,
168
+                        'default'        => $default,
169
+                        'wrapper_attrs'  => $wrapper_attrs,
170
+                        'choices'        => array(
171
+                            'label_position' => 'bottom',
172
+                        ),
173
+                        'js_vars'        => array(),
174
+                        'css_vars'       => array(),
175
+                        'output'         => array(),
176
+                    ),
177
+                    $args
178
+                )
179
+            );
180
+        }
181
+
182
+    }
183
+
184
+    /**
185
+     * Sanitizes dimension controls.
186
+     *
187
+     * @static
188
+     * @access public
189
+     * @since 1.0
190
+     * @param array $value The value.
191
+     * @return array
192
+     */
193
+    public static function sanitize( $value ) {
194
+
195
+        if ( ! is_array( $value ) ) {
196
+            return array();
197
+        }
198
+
199
+        foreach ( $value as $key => $val ) {
200
+            $value[ $key ] = sanitize_text_field( $val );
201
+        }
202
+
203
+        return $value;
204
+
205
+    }
206
+
207
+    /**
208
+     * Override parent method. No need to register any setting.
209
+     *
210
+     * @access public
211
+     * @since 0.1
212
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
213
+     * @return void
214
+     */
215
+    public function add_setting( $wp_customize ) {}
216
+
217
+    /**
218
+     * Override the parent method. No need for a control.
219
+     *
220
+     * @access public
221
+     * @since 0.1
222
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
223
+     * @return void
224
+     */
225
+    public function add_control( $wp_customize ) {}
226
+
227
+    /**
228
+     * Enqueue scripts & styles.
229
+     *
230
+     * @access public
231
+     * @since 1.0
232
+     * @return void
233
+     */
234
+    public function enqueue_scripts() {
235
+
236
+        wp_enqueue_style( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) . '/dist/control.css' ), array(), '1.0' );
237
+
238
+    }
239
+
240
+    /**
241
+     * Enqueue scripts & styles on customize_preview_init.
242
+     *
243
+     * @access public
244
+     * @since 1.0
245
+     * @return void
246
+     */
247
+    public function enqueue_customize_preview_scripts() {
248
+
249
+        wp_enqueue_script( 'kirki-field-dimensions', URL::get_from_path( dirname( __DIR__ ) ) . '/dist/preview.js', array( 'wp-hooks' ), '1.0', true );
250
+
251
+    }
252
+
253
+    /**
254
+     * Adds a custom output class for typography fields.
255
+     *
256
+     * @access public
257
+     * @since 1.0
258
+     * @param array $classnames The array of classnames.
259
+     * @return array
260
+     */
261
+    public function output_control_classnames( $classnames ) {
262
+
263
+        $classnames['kirki-dimensions'] = '\Kirki\Field\CSS\Dimensions';
264
+        return $classnames;
265
+
266
+    }
267 267
 }
Please login to merge, or discard this patch.