@@ -18,50 +18,50 @@ |
||
18 | 18 | */ |
19 | 19 | class Preset { |
20 | 20 | |
21 | - /** |
|
22 | - * An array of preset controls and their arguments. |
|
23 | - * |
|
24 | - * @static |
|
25 | - * @access private |
|
26 | - * @since 1.0.0 |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - private static $preset_controls = []; |
|
21 | + /** |
|
22 | + * An array of preset controls and their arguments. |
|
23 | + * |
|
24 | + * @static |
|
25 | + * @access private |
|
26 | + * @since 1.0.0 |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + private static $preset_controls = []; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor. |
|
33 | - * |
|
34 | - * @access public |
|
35 | - * @since 1.0.0 |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - add_action( 'customize_controls_print_footer_scripts', [ $this, 'customize_controls_print_footer_scripts' ] ); |
|
39 | - add_filter( 'kirki_field_add_control_args', [ $this, 'field_add_control_args' ] ); |
|
40 | - } |
|
31 | + /** |
|
32 | + * Constructor. |
|
33 | + * |
|
34 | + * @access public |
|
35 | + * @since 1.0.0 |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + add_action( 'customize_controls_print_footer_scripts', [ $this, 'customize_controls_print_footer_scripts' ] ); |
|
39 | + add_filter( 'kirki_field_add_control_args', [ $this, 'field_add_control_args' ] ); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Filter control arguments. |
|
44 | - * |
|
45 | - * @access public |
|
46 | - * @since 1.0 |
|
47 | - * @param array $args The field arguments. |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function field_add_control_args( $args ) { |
|
51 | - if ( isset( $args['preset'] ) && is_array( $args['preset'] ) ) { |
|
52 | - self::$preset_controls[ $args['settings'] ] = $args['preset']; |
|
53 | - } |
|
54 | - return $args; |
|
55 | - } |
|
42 | + /** |
|
43 | + * Filter control arguments. |
|
44 | + * |
|
45 | + * @access public |
|
46 | + * @since 1.0 |
|
47 | + * @param array $args The field arguments. |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function field_add_control_args( $args ) { |
|
51 | + if ( isset( $args['preset'] ) && is_array( $args['preset'] ) ) { |
|
52 | + self::$preset_controls[ $args['settings'] ] = $args['preset']; |
|
53 | + } |
|
54 | + return $args; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Enqueue scripts. |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @since 1.0.0 |
|
62 | - */ |
|
63 | - public function customize_controls_print_footer_scripts() { |
|
64 | - wp_enqueue_script( 'kirki-preset', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery' ], '1.0.0', false ); |
|
65 | - wp_localize_script( 'kirki-preset', 'kirkiPresetControls', self::$preset_controls ); |
|
66 | - } |
|
57 | + /** |
|
58 | + * Enqueue scripts. |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @since 1.0.0 |
|
62 | + */ |
|
63 | + public function customize_controls_print_footer_scripts() { |
|
64 | + wp_enqueue_script( 'kirki-preset', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery' ], '1.0.0', false ); |
|
65 | + wp_localize_script( 'kirki-preset', 'kirkiPresetControls', self::$preset_controls ); |
|
66 | + } |
|
67 | 67 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | - add_action( 'customize_controls_print_footer_scripts', [ $this, 'customize_controls_print_footer_scripts' ] ); |
|
39 | - add_filter( 'kirki_field_add_control_args', [ $this, 'field_add_control_args' ] ); |
|
38 | + add_action('customize_controls_print_footer_scripts', [$this, 'customize_controls_print_footer_scripts']); |
|
39 | + add_filter('kirki_field_add_control_args', [$this, 'field_add_control_args']); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $args The field arguments. |
48 | 48 | * @return array |
49 | 49 | */ |
50 | - public function field_add_control_args( $args ) { |
|
51 | - if ( isset( $args['preset'] ) && is_array( $args['preset'] ) ) { |
|
52 | - self::$preset_controls[ $args['settings'] ] = $args['preset']; |
|
50 | + public function field_add_control_args($args) { |
|
51 | + if (isset($args['preset']) && is_array($args['preset'])) { |
|
52 | + self::$preset_controls[$args['settings']] = $args['preset']; |
|
53 | 53 | } |
54 | 54 | return $args; |
55 | 55 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @since 1.0.0 |
62 | 62 | */ |
63 | 63 | public function customize_controls_print_footer_scripts() { |
64 | - wp_enqueue_script( 'kirki-preset', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery' ], '1.0.0', false ); |
|
65 | - wp_localize_script( 'kirki-preset', 'kirkiPresetControls', self::$preset_controls ); |
|
64 | + wp_enqueue_script('kirki-preset', URL::get_from_path(__DIR__ . '/script.js'), ['jquery'], '1.0.0', false); |
|
65 | + wp_localize_script('kirki-preset', 'kirkiPresetControls', self::$preset_controls); |
|
66 | 66 | } |
67 | 67 | } |
@@ -18,41 +18,41 @@ |
||
18 | 18 | */ |
19 | 19 | class Multicolor extends Output { |
20 | 20 | |
21 | - /** |
|
22 | - * Processes a single item from the `output` array. |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @param array $output The `output` item. |
|
26 | - * @param array $value The field's value. |
|
27 | - */ |
|
28 | - protected function process_output( $output, $value ) { |
|
29 | - |
|
30 | - foreach ( $value as $key => $sub_value ) { |
|
31 | - |
|
32 | - // If "element" is not defined, there's no reason to continue. |
|
33 | - if ( ! isset( $output['element'] ) ) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - |
|
37 | - // If the "choice" is not the same as the $key in our loop, there's no reason to proceed. |
|
38 | - if ( isset( $output['choice'] ) && $key !== $output['choice'] ) { |
|
39 | - continue; |
|
40 | - } |
|
41 | - |
|
42 | - // If "property" is not defined, fallback to the $key. |
|
43 | - $property = ( ! isset( $output['property'] ) || empty( $output['property'] ) ) ? $key : $output['property']; |
|
44 | - |
|
45 | - // If "media_query" is not defined, use "global". |
|
46 | - if ( ! isset( $output['media_query'] ) || empty( $output['media_query'] ) ) { |
|
47 | - $output['media_query'] = 'global'; |
|
48 | - } |
|
49 | - |
|
50 | - // If "suffix" is defined, add it to the value. |
|
51 | - $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; |
|
52 | - |
|
53 | - // Create the styles. |
|
54 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $sub_value . $output['suffix']; |
|
55 | - |
|
56 | - } |
|
57 | - } |
|
21 | + /** |
|
22 | + * Processes a single item from the `output` array. |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @param array $output The `output` item. |
|
26 | + * @param array $value The field's value. |
|
27 | + */ |
|
28 | + protected function process_output( $output, $value ) { |
|
29 | + |
|
30 | + foreach ( $value as $key => $sub_value ) { |
|
31 | + |
|
32 | + // If "element" is not defined, there's no reason to continue. |
|
33 | + if ( ! isset( $output['element'] ) ) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + |
|
37 | + // If the "choice" is not the same as the $key in our loop, there's no reason to proceed. |
|
38 | + if ( isset( $output['choice'] ) && $key !== $output['choice'] ) { |
|
39 | + continue; |
|
40 | + } |
|
41 | + |
|
42 | + // If "property" is not defined, fallback to the $key. |
|
43 | + $property = ( ! isset( $output['property'] ) || empty( $output['property'] ) ) ? $key : $output['property']; |
|
44 | + |
|
45 | + // If "media_query" is not defined, use "global". |
|
46 | + if ( ! isset( $output['media_query'] ) || empty( $output['media_query'] ) ) { |
|
47 | + $output['media_query'] = 'global'; |
|
48 | + } |
|
49 | + |
|
50 | + // If "suffix" is defined, add it to the value. |
|
51 | + $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; |
|
52 | + |
|
53 | + // Create the styles. |
|
54 | + $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $sub_value . $output['suffix']; |
|
55 | + |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -25,33 +25,33 @@ |
||
25 | 25 | * @param array $output The `output` item. |
26 | 26 | * @param array $value The field's value. |
27 | 27 | */ |
28 | - protected function process_output( $output, $value ) { |
|
28 | + protected function process_output($output, $value) { |
|
29 | 29 | |
30 | - foreach ( $value as $key => $sub_value ) { |
|
30 | + foreach ($value as $key => $sub_value) { |
|
31 | 31 | |
32 | 32 | // If "element" is not defined, there's no reason to continue. |
33 | - if ( ! isset( $output['element'] ) ) { |
|
33 | + if (!isset($output['element'])) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | 36 | |
37 | 37 | // If the "choice" is not the same as the $key in our loop, there's no reason to proceed. |
38 | - if ( isset( $output['choice'] ) && $key !== $output['choice'] ) { |
|
38 | + if (isset($output['choice']) && $key !== $output['choice']) { |
|
39 | 39 | continue; |
40 | 40 | } |
41 | 41 | |
42 | 42 | // If "property" is not defined, fallback to the $key. |
43 | - $property = ( ! isset( $output['property'] ) || empty( $output['property'] ) ) ? $key : $output['property']; |
|
43 | + $property = (!isset($output['property']) || empty($output['property'])) ? $key : $output['property']; |
|
44 | 44 | |
45 | 45 | // If "media_query" is not defined, use "global". |
46 | - if ( ! isset( $output['media_query'] ) || empty( $output['media_query'] ) ) { |
|
46 | + if (!isset($output['media_query']) || empty($output['media_query'])) { |
|
47 | 47 | $output['media_query'] = 'global'; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // If "suffix" is defined, add it to the value. |
51 | - $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; |
|
51 | + $output['suffix'] = (isset($output['suffix'])) ? $output['suffix'] : ''; |
|
52 | 52 | |
53 | 53 | // Create the styles. |
54 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $sub_value . $output['suffix']; |
|
54 | + $this->styles[$output['media_query']][$output['element']][$property] = $sub_value . $output['suffix']; |
|
55 | 55 | |
56 | 56 | } |
57 | 57 | } |
@@ -19,241 +19,241 @@ |
||
19 | 19 | */ |
20 | 20 | class Multicolor 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-multicolor'; |
|
30 | - |
|
31 | - /** |
|
32 | - * Extra logic for the field. |
|
33 | - * |
|
34 | - * Adds all sub-fields. |
|
35 | - * |
|
36 | - * @access public |
|
37 | - * @param array $args The arguments of the field. |
|
38 | - */ |
|
39 | - public function init( $args ) { |
|
40 | - |
|
41 | - add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
42 | - |
|
43 | - $parent_control_args = wp_parse_args( |
|
44 | - [ |
|
45 | - 'type' => 'kirki-generic', |
|
46 | - 'default' => '', |
|
47 | - 'wrapper_opts' => [ |
|
48 | - 'gap' => 'small', |
|
49 | - ], |
|
50 | - 'input_attrs' => '', |
|
51 | - 'choices' => [ |
|
52 | - 'type' => 'hidden', |
|
53 | - 'parent_type' => 'kirki-multicolor', |
|
54 | - ], |
|
55 | - 'sanitize_callback' => [ __CLASS__, 'sanitize' ], |
|
56 | - ], |
|
57 | - $args |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Add a hidden field, the label & description. |
|
62 | - */ |
|
63 | - new \Kirki\Field\Generic( $parent_control_args ); |
|
64 | - |
|
65 | - $total_colors = count( $args['choices'] ); |
|
66 | - $loop_index = 0; |
|
67 | - |
|
68 | - $use_alpha = $this->filter_preferred_choice_setting( 'alpha', null, $args ) ? true : false; |
|
69 | - $swatches = $this->filter_preferred_choice_setting( 'swatches', null, $args ); |
|
70 | - $swatches = empty( $swatches ) ? $this->filter_preferred_choice_setting( 'palettes', null, $args ) : $swatches; |
|
71 | - $swatches = empty( $swatches ) ? [] : $swatches; |
|
72 | - |
|
73 | - if ( empty( $swatches ) ) { |
|
74 | - $swatches = isset( $args['palettes'] ) && ! empty( $args['palettes'] ) ? $args['palettes'] : []; |
|
75 | - } |
|
76 | - |
|
77 | - foreach ( $args['choices'] as $choice => $choice_label ) { |
|
78 | - $loop_index++; |
|
79 | - |
|
80 | - $classnames = '{default_class} kirki-group-item'; |
|
81 | - $classnames .= 1 === $loop_index ? ' kirki-group-start' : ( $loop_index === $total_colors ? ' kirki-group-end' : $classnames ); |
|
82 | - |
|
83 | - $use_alpha_per_choice = $this->filter_preferred_choice_setting( 'alpha', $choice, $args ) ? true : $use_alpha; |
|
84 | - $swatches_per_choice = $this->filter_preferred_choice_setting( 'swatches', $choice, $args ); |
|
85 | - $swatches_per_choice = empty( $swatches_per_choice ) ? $this->filter_preferred_choice_setting( 'palettes', $choice, $args ) : $swatches_per_choice; |
|
86 | - $swatches_per_choice = empty( $swatches_per_choice ) ? $swatches : $swatches_per_choice; |
|
87 | - |
|
88 | - $control_args = wp_parse_args( |
|
89 | - [ |
|
90 | - 'settings' => $args['settings'] . '[' . $choice . ']', |
|
91 | - 'parent_setting' => $args['settings'], |
|
92 | - 'label' => $choice_label, |
|
93 | - 'description' => '', |
|
94 | - 'default' => $this->filter_preferred_choice_setting( 'default', $choice, $args ), |
|
95 | - 'wrapper_attrs' => [ |
|
96 | - 'data-kirki-parent-control-type' => 'kirki-multicolor', |
|
97 | - 'class' => $classnames, |
|
98 | - ], |
|
99 | - 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $choice, $args ), |
|
100 | - 'choices' => [ |
|
101 | - 'alpha' => $use_alpha_per_choice, |
|
102 | - 'label_style' => 'tooltip', |
|
103 | - 'swatches' => $swatches_per_choice, |
|
104 | - ], |
|
105 | - 'css_vars' => [], |
|
106 | - 'output' => [], |
|
107 | - ], |
|
108 | - $args |
|
109 | - ); |
|
110 | - |
|
111 | - foreach ( $control_args['choices'] as $control_choice_id => $control_choice_value ) { |
|
112 | - if ( isset( $control_args[ $control_choice_id ] ) ) { |
|
113 | - unset( $control_args[ $control_choice_id ] ); |
|
114 | - } else { |
|
115 | - if ( 'swatches' === $control_choice_id || 'palettes' === $control_choice_id ) { |
|
116 | - if ( isset( $control_args['palettes'] ) ) { |
|
117 | - unset( $control_args['palettes'] ); |
|
118 | - } |
|
119 | - |
|
120 | - if ( isset( $control_args['swatches'] ) ) { |
|
121 | - unset( $control_args['swatches'] ); |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - new \Kirki\Field\ReactColorful( $control_args ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prefer control specific value over field value |
|
133 | - * |
|
134 | - * @access public |
|
135 | - * @since 4.0 |
|
136 | - * |
|
137 | - * @param string $setting The argument key inside $args. |
|
138 | - * @param string $choice The choice key inside $args['choices']. |
|
139 | - * @param array $args The arguments. |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function filter_preferred_choice_setting( $setting, $choice, $args ) { |
|
144 | - |
|
145 | - // Fail early. |
|
146 | - if ( ! isset( $args[ $setting ] ) ) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - |
|
150 | - if ( null === $choice ) { |
|
151 | - $per_choice_found = false; |
|
152 | - |
|
153 | - foreach ( $args['choices'] as $choice_id => $choice_label ) { |
|
154 | - if ( isset( $args[ $setting ][ $choice_id ] ) ) { |
|
155 | - $per_choice_found = true; |
|
156 | - break; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - if ( ! $per_choice_found ) { |
|
161 | - return $args[ $setting ]; |
|
162 | - } |
|
163 | - |
|
164 | - return ''; |
|
165 | - } |
|
166 | - |
|
167 | - // If a specific field for the choice is set. |
|
168 | - if ( isset( $args[ $setting ][ $choice ] ) ) { |
|
169 | - return $args[ $setting ][ $choice ]; |
|
170 | - } |
|
171 | - |
|
172 | - // Unset all other choices. |
|
173 | - foreach ( $args['choices'] as $id => $set ) { |
|
174 | - if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) { |
|
175 | - unset( $args[ $setting ][ $id ] ); |
|
176 | - } elseif ( ! isset( $args[ $setting ][ $id ] ) ) { |
|
177 | - $args[ $setting ] = ''; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - return $args[ $setting ]; |
|
182 | - |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Filter arguments before creating the setting. |
|
187 | - * |
|
188 | - * @access public |
|
189 | - * @since 0.1 |
|
190 | - * @param array $args The field arguments. |
|
191 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function filter_setting_args( $args, $wp_customize ) { |
|
195 | - |
|
196 | - if ( $args['settings'] !== $this->args['settings'] ) { |
|
197 | - return $args; |
|
198 | - } |
|
199 | - |
|
200 | - // Set the sanitize-callback if none is defined. |
|
201 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
202 | - $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
203 | - } |
|
204 | - |
|
205 | - return $args; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Sanitizes background controls |
|
210 | - * |
|
211 | - * @static |
|
212 | - * @access public |
|
213 | - * @since 1.0 |
|
214 | - * @param array $value The value. |
|
215 | - * @return array |
|
216 | - */ |
|
217 | - public static function sanitize( $value ) { |
|
218 | - |
|
219 | - foreach ( $value as $key => $subvalue ) { |
|
220 | - $value[ $key ] = \Kirki\Field\Color::sanitize( $subvalue ); |
|
221 | - } |
|
222 | - |
|
223 | - return $value; |
|
224 | - |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Override parent method. No need to register any setting. |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @since 0.1 |
|
232 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
233 | - * @return void |
|
234 | - */ |
|
235 | - public function add_setting( $wp_customize ) {} |
|
236 | - |
|
237 | - /** |
|
238 | - * Override the parent method. No need for a control. |
|
239 | - * |
|
240 | - * @access public |
|
241 | - * @since 0.1 |
|
242 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - public function add_control( $wp_customize ) {} |
|
246 | - |
|
247 | - /** |
|
248 | - * Adds a custom output class for typography fields. |
|
249 | - * |
|
250 | - * @access public |
|
251 | - * @since 1.0 |
|
252 | - * @param array $classnames The array of classnames. |
|
253 | - * @return array |
|
254 | - */ |
|
255 | - public function output_control_classnames( $classnames ) { |
|
256 | - $classnames['kirki-multicolor'] = '\Kirki\Field\CSS\Multicolor'; |
|
257 | - return $classnames; |
|
258 | - } |
|
22 | + /** |
|
23 | + * The field type. |
|
24 | + * |
|
25 | + * @access public |
|
26 | + * @since 1.0 |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $type = 'kirki-multicolor'; |
|
30 | + |
|
31 | + /** |
|
32 | + * Extra logic for the field. |
|
33 | + * |
|
34 | + * Adds all sub-fields. |
|
35 | + * |
|
36 | + * @access public |
|
37 | + * @param array $args The arguments of the field. |
|
38 | + */ |
|
39 | + public function init( $args ) { |
|
40 | + |
|
41 | + add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
42 | + |
|
43 | + $parent_control_args = wp_parse_args( |
|
44 | + [ |
|
45 | + 'type' => 'kirki-generic', |
|
46 | + 'default' => '', |
|
47 | + 'wrapper_opts' => [ |
|
48 | + 'gap' => 'small', |
|
49 | + ], |
|
50 | + 'input_attrs' => '', |
|
51 | + 'choices' => [ |
|
52 | + 'type' => 'hidden', |
|
53 | + 'parent_type' => 'kirki-multicolor', |
|
54 | + ], |
|
55 | + 'sanitize_callback' => [ __CLASS__, 'sanitize' ], |
|
56 | + ], |
|
57 | + $args |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Add a hidden field, the label & description. |
|
62 | + */ |
|
63 | + new \Kirki\Field\Generic( $parent_control_args ); |
|
64 | + |
|
65 | + $total_colors = count( $args['choices'] ); |
|
66 | + $loop_index = 0; |
|
67 | + |
|
68 | + $use_alpha = $this->filter_preferred_choice_setting( 'alpha', null, $args ) ? true : false; |
|
69 | + $swatches = $this->filter_preferred_choice_setting( 'swatches', null, $args ); |
|
70 | + $swatches = empty( $swatches ) ? $this->filter_preferred_choice_setting( 'palettes', null, $args ) : $swatches; |
|
71 | + $swatches = empty( $swatches ) ? [] : $swatches; |
|
72 | + |
|
73 | + if ( empty( $swatches ) ) { |
|
74 | + $swatches = isset( $args['palettes'] ) && ! empty( $args['palettes'] ) ? $args['palettes'] : []; |
|
75 | + } |
|
76 | + |
|
77 | + foreach ( $args['choices'] as $choice => $choice_label ) { |
|
78 | + $loop_index++; |
|
79 | + |
|
80 | + $classnames = '{default_class} kirki-group-item'; |
|
81 | + $classnames .= 1 === $loop_index ? ' kirki-group-start' : ( $loop_index === $total_colors ? ' kirki-group-end' : $classnames ); |
|
82 | + |
|
83 | + $use_alpha_per_choice = $this->filter_preferred_choice_setting( 'alpha', $choice, $args ) ? true : $use_alpha; |
|
84 | + $swatches_per_choice = $this->filter_preferred_choice_setting( 'swatches', $choice, $args ); |
|
85 | + $swatches_per_choice = empty( $swatches_per_choice ) ? $this->filter_preferred_choice_setting( 'palettes', $choice, $args ) : $swatches_per_choice; |
|
86 | + $swatches_per_choice = empty( $swatches_per_choice ) ? $swatches : $swatches_per_choice; |
|
87 | + |
|
88 | + $control_args = wp_parse_args( |
|
89 | + [ |
|
90 | + 'settings' => $args['settings'] . '[' . $choice . ']', |
|
91 | + 'parent_setting' => $args['settings'], |
|
92 | + 'label' => $choice_label, |
|
93 | + 'description' => '', |
|
94 | + 'default' => $this->filter_preferred_choice_setting( 'default', $choice, $args ), |
|
95 | + 'wrapper_attrs' => [ |
|
96 | + 'data-kirki-parent-control-type' => 'kirki-multicolor', |
|
97 | + 'class' => $classnames, |
|
98 | + ], |
|
99 | + 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $choice, $args ), |
|
100 | + 'choices' => [ |
|
101 | + 'alpha' => $use_alpha_per_choice, |
|
102 | + 'label_style' => 'tooltip', |
|
103 | + 'swatches' => $swatches_per_choice, |
|
104 | + ], |
|
105 | + 'css_vars' => [], |
|
106 | + 'output' => [], |
|
107 | + ], |
|
108 | + $args |
|
109 | + ); |
|
110 | + |
|
111 | + foreach ( $control_args['choices'] as $control_choice_id => $control_choice_value ) { |
|
112 | + if ( isset( $control_args[ $control_choice_id ] ) ) { |
|
113 | + unset( $control_args[ $control_choice_id ] ); |
|
114 | + } else { |
|
115 | + if ( 'swatches' === $control_choice_id || 'palettes' === $control_choice_id ) { |
|
116 | + if ( isset( $control_args['palettes'] ) ) { |
|
117 | + unset( $control_args['palettes'] ); |
|
118 | + } |
|
119 | + |
|
120 | + if ( isset( $control_args['swatches'] ) ) { |
|
121 | + unset( $control_args['swatches'] ); |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + new \Kirki\Field\ReactColorful( $control_args ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prefer control specific value over field value |
|
133 | + * |
|
134 | + * @access public |
|
135 | + * @since 4.0 |
|
136 | + * |
|
137 | + * @param string $setting The argument key inside $args. |
|
138 | + * @param string $choice The choice key inside $args['choices']. |
|
139 | + * @param array $args The arguments. |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function filter_preferred_choice_setting( $setting, $choice, $args ) { |
|
144 | + |
|
145 | + // Fail early. |
|
146 | + if ( ! isset( $args[ $setting ] ) ) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + |
|
150 | + if ( null === $choice ) { |
|
151 | + $per_choice_found = false; |
|
152 | + |
|
153 | + foreach ( $args['choices'] as $choice_id => $choice_label ) { |
|
154 | + if ( isset( $args[ $setting ][ $choice_id ] ) ) { |
|
155 | + $per_choice_found = true; |
|
156 | + break; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + if ( ! $per_choice_found ) { |
|
161 | + return $args[ $setting ]; |
|
162 | + } |
|
163 | + |
|
164 | + return ''; |
|
165 | + } |
|
166 | + |
|
167 | + // If a specific field for the choice is set. |
|
168 | + if ( isset( $args[ $setting ][ $choice ] ) ) { |
|
169 | + return $args[ $setting ][ $choice ]; |
|
170 | + } |
|
171 | + |
|
172 | + // Unset all other choices. |
|
173 | + foreach ( $args['choices'] as $id => $set ) { |
|
174 | + if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) { |
|
175 | + unset( $args[ $setting ][ $id ] ); |
|
176 | + } elseif ( ! isset( $args[ $setting ][ $id ] ) ) { |
|
177 | + $args[ $setting ] = ''; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + return $args[ $setting ]; |
|
182 | + |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Filter arguments before creating the setting. |
|
187 | + * |
|
188 | + * @access public |
|
189 | + * @since 0.1 |
|
190 | + * @param array $args The field arguments. |
|
191 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function filter_setting_args( $args, $wp_customize ) { |
|
195 | + |
|
196 | + if ( $args['settings'] !== $this->args['settings'] ) { |
|
197 | + return $args; |
|
198 | + } |
|
199 | + |
|
200 | + // Set the sanitize-callback if none is defined. |
|
201 | + if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
202 | + $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
203 | + } |
|
204 | + |
|
205 | + return $args; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Sanitizes background controls |
|
210 | + * |
|
211 | + * @static |
|
212 | + * @access public |
|
213 | + * @since 1.0 |
|
214 | + * @param array $value The value. |
|
215 | + * @return array |
|
216 | + */ |
|
217 | + public static function sanitize( $value ) { |
|
218 | + |
|
219 | + foreach ( $value as $key => $subvalue ) { |
|
220 | + $value[ $key ] = \Kirki\Field\Color::sanitize( $subvalue ); |
|
221 | + } |
|
222 | + |
|
223 | + return $value; |
|
224 | + |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Override parent method. No need to register any setting. |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @since 0.1 |
|
232 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
233 | + * @return void |
|
234 | + */ |
|
235 | + public function add_setting( $wp_customize ) {} |
|
236 | + |
|
237 | + /** |
|
238 | + * Override the parent method. No need for a control. |
|
239 | + * |
|
240 | + * @access public |
|
241 | + * @since 0.1 |
|
242 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + public function add_control( $wp_customize ) {} |
|
246 | + |
|
247 | + /** |
|
248 | + * Adds a custom output class for typography fields. |
|
249 | + * |
|
250 | + * @access public |
|
251 | + * @since 1.0 |
|
252 | + * @param array $classnames The array of classnames. |
|
253 | + * @return array |
|
254 | + */ |
|
255 | + public function output_control_classnames( $classnames ) { |
|
256 | + $classnames['kirki-multicolor'] = '\Kirki\Field\CSS\Multicolor'; |
|
257 | + return $classnames; |
|
258 | + } |
|
259 | 259 | } |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * @access public |
37 | 37 | * @param array $args The arguments of the field. |
38 | 38 | */ |
39 | - public function init( $args ) { |
|
39 | + public function init($args) { |
|
40 | 40 | |
41 | - add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
41 | + add_filter('kirki_output_control_classnames', [$this, 'output_control_classnames']); |
|
42 | 42 | |
43 | 43 | $parent_control_args = wp_parse_args( |
44 | 44 | [ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'type' => 'hidden', |
53 | 53 | 'parent_type' => 'kirki-multicolor', |
54 | 54 | ], |
55 | - 'sanitize_callback' => [ __CLASS__, 'sanitize' ], |
|
55 | + 'sanitize_callback' => [__CLASS__, 'sanitize'], |
|
56 | 56 | ], |
57 | 57 | $args |
58 | 58 | ); |
@@ -60,30 +60,30 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Add a hidden field, the label & description. |
62 | 62 | */ |
63 | - new \Kirki\Field\Generic( $parent_control_args ); |
|
63 | + new \Kirki\Field\Generic($parent_control_args); |
|
64 | 64 | |
65 | - $total_colors = count( $args['choices'] ); |
|
65 | + $total_colors = count($args['choices']); |
|
66 | 66 | $loop_index = 0; |
67 | 67 | |
68 | - $use_alpha = $this->filter_preferred_choice_setting( 'alpha', null, $args ) ? true : false; |
|
69 | - $swatches = $this->filter_preferred_choice_setting( 'swatches', null, $args ); |
|
70 | - $swatches = empty( $swatches ) ? $this->filter_preferred_choice_setting( 'palettes', null, $args ) : $swatches; |
|
71 | - $swatches = empty( $swatches ) ? [] : $swatches; |
|
68 | + $use_alpha = $this->filter_preferred_choice_setting('alpha', null, $args) ? true : false; |
|
69 | + $swatches = $this->filter_preferred_choice_setting('swatches', null, $args); |
|
70 | + $swatches = empty($swatches) ? $this->filter_preferred_choice_setting('palettes', null, $args) : $swatches; |
|
71 | + $swatches = empty($swatches) ? [] : $swatches; |
|
72 | 72 | |
73 | - if ( empty( $swatches ) ) { |
|
74 | - $swatches = isset( $args['palettes'] ) && ! empty( $args['palettes'] ) ? $args['palettes'] : []; |
|
73 | + if (empty($swatches)) { |
|
74 | + $swatches = isset($args['palettes']) && !empty($args['palettes']) ? $args['palettes'] : []; |
|
75 | 75 | } |
76 | 76 | |
77 | - foreach ( $args['choices'] as $choice => $choice_label ) { |
|
77 | + foreach ($args['choices'] as $choice => $choice_label) { |
|
78 | 78 | $loop_index++; |
79 | 79 | |
80 | 80 | $classnames = '{default_class} kirki-group-item'; |
81 | - $classnames .= 1 === $loop_index ? ' kirki-group-start' : ( $loop_index === $total_colors ? ' kirki-group-end' : $classnames ); |
|
81 | + $classnames .= 1 === $loop_index ? ' kirki-group-start' : ($loop_index === $total_colors ? ' kirki-group-end' : $classnames); |
|
82 | 82 | |
83 | - $use_alpha_per_choice = $this->filter_preferred_choice_setting( 'alpha', $choice, $args ) ? true : $use_alpha; |
|
84 | - $swatches_per_choice = $this->filter_preferred_choice_setting( 'swatches', $choice, $args ); |
|
85 | - $swatches_per_choice = empty( $swatches_per_choice ) ? $this->filter_preferred_choice_setting( 'palettes', $choice, $args ) : $swatches_per_choice; |
|
86 | - $swatches_per_choice = empty( $swatches_per_choice ) ? $swatches : $swatches_per_choice; |
|
83 | + $use_alpha_per_choice = $this->filter_preferred_choice_setting('alpha', $choice, $args) ? true : $use_alpha; |
|
84 | + $swatches_per_choice = $this->filter_preferred_choice_setting('swatches', $choice, $args); |
|
85 | + $swatches_per_choice = empty($swatches_per_choice) ? $this->filter_preferred_choice_setting('palettes', $choice, $args) : $swatches_per_choice; |
|
86 | + $swatches_per_choice = empty($swatches_per_choice) ? $swatches : $swatches_per_choice; |
|
87 | 87 | |
88 | 88 | $control_args = wp_parse_args( |
89 | 89 | [ |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | 'parent_setting' => $args['settings'], |
92 | 92 | 'label' => $choice_label, |
93 | 93 | 'description' => '', |
94 | - 'default' => $this->filter_preferred_choice_setting( 'default', $choice, $args ), |
|
94 | + 'default' => $this->filter_preferred_choice_setting('default', $choice, $args), |
|
95 | 95 | 'wrapper_attrs' => [ |
96 | 96 | 'data-kirki-parent-control-type' => 'kirki-multicolor', |
97 | 97 | 'class' => $classnames, |
98 | 98 | ], |
99 | - 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $choice, $args ), |
|
99 | + 'input_attrs' => $this->filter_preferred_choice_setting('input_attrs', $choice, $args), |
|
100 | 100 | 'choices' => [ |
101 | 101 | 'alpha' => $use_alpha_per_choice, |
102 | 102 | 'label_style' => 'tooltip', |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | $args |
109 | 109 | ); |
110 | 110 | |
111 | - foreach ( $control_args['choices'] as $control_choice_id => $control_choice_value ) { |
|
112 | - if ( isset( $control_args[ $control_choice_id ] ) ) { |
|
113 | - unset( $control_args[ $control_choice_id ] ); |
|
111 | + foreach ($control_args['choices'] as $control_choice_id => $control_choice_value) { |
|
112 | + if (isset($control_args[$control_choice_id])) { |
|
113 | + unset($control_args[$control_choice_id]); |
|
114 | 114 | } else { |
115 | - if ( 'swatches' === $control_choice_id || 'palettes' === $control_choice_id ) { |
|
116 | - if ( isset( $control_args['palettes'] ) ) { |
|
117 | - unset( $control_args['palettes'] ); |
|
115 | + if ('swatches' === $control_choice_id || 'palettes' === $control_choice_id) { |
|
116 | + if (isset($control_args['palettes'])) { |
|
117 | + unset($control_args['palettes']); |
|
118 | 118 | } |
119 | 119 | |
120 | - if ( isset( $control_args['swatches'] ) ) { |
|
121 | - unset( $control_args['swatches'] ); |
|
120 | + if (isset($control_args['swatches'])) { |
|
121 | + unset($control_args['swatches']); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - new \Kirki\Field\ReactColorful( $control_args ); |
|
127 | + new \Kirki\Field\ReactColorful($control_args); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
@@ -140,45 +140,45 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function filter_preferred_choice_setting( $setting, $choice, $args ) { |
|
143 | + public function filter_preferred_choice_setting($setting, $choice, $args) { |
|
144 | 144 | |
145 | 145 | // Fail early. |
146 | - if ( ! isset( $args[ $setting ] ) ) { |
|
146 | + if (!isset($args[$setting])) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | |
150 | - if ( null === $choice ) { |
|
150 | + if (null === $choice) { |
|
151 | 151 | $per_choice_found = false; |
152 | 152 | |
153 | - foreach ( $args['choices'] as $choice_id => $choice_label ) { |
|
154 | - if ( isset( $args[ $setting ][ $choice_id ] ) ) { |
|
153 | + foreach ($args['choices'] as $choice_id => $choice_label) { |
|
154 | + if (isset($args[$setting][$choice_id])) { |
|
155 | 155 | $per_choice_found = true; |
156 | 156 | break; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - if ( ! $per_choice_found ) { |
|
161 | - return $args[ $setting ]; |
|
160 | + if (!$per_choice_found) { |
|
161 | + return $args[$setting]; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return ''; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // If a specific field for the choice is set. |
168 | - if ( isset( $args[ $setting ][ $choice ] ) ) { |
|
169 | - return $args[ $setting ][ $choice ]; |
|
168 | + if (isset($args[$setting][$choice])) { |
|
169 | + return $args[$setting][$choice]; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Unset all other choices. |
173 | - foreach ( $args['choices'] as $id => $set ) { |
|
174 | - if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) { |
|
175 | - unset( $args[ $setting ][ $id ] ); |
|
176 | - } elseif ( ! isset( $args[ $setting ][ $id ] ) ) { |
|
177 | - $args[ $setting ] = ''; |
|
173 | + foreach ($args['choices'] as $id => $set) { |
|
174 | + if ($id !== $choice && isset($args[$setting][$id])) { |
|
175 | + unset($args[$setting][$id]); |
|
176 | + } elseif (!isset($args[$setting][$id])) { |
|
177 | + $args[$setting] = ''; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - return $args[ $setting ]; |
|
181 | + return $args[$setting]; |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
@@ -191,15 +191,15 @@ discard block |
||
191 | 191 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
192 | 192 | * @return array |
193 | 193 | */ |
194 | - public function filter_setting_args( $args, $wp_customize ) { |
|
194 | + public function filter_setting_args($args, $wp_customize) { |
|
195 | 195 | |
196 | - if ( $args['settings'] !== $this->args['settings'] ) { |
|
196 | + if ($args['settings'] !== $this->args['settings']) { |
|
197 | 197 | return $args; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Set the sanitize-callback if none is defined. |
201 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
202 | - $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
201 | + if (!isset($args['sanitize_callback']) || !$args['sanitize_callback']) { |
|
202 | + $args['sanitize_callback'] = [__CLASS__, 'sanitize']; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $args; |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | * @param array $value The value. |
215 | 215 | * @return array |
216 | 216 | */ |
217 | - public static function sanitize( $value ) { |
|
217 | + public static function sanitize($value) { |
|
218 | 218 | |
219 | - foreach ( $value as $key => $subvalue ) { |
|
220 | - $value[ $key ] = \Kirki\Field\Color::sanitize( $subvalue ); |
|
219 | + foreach ($value as $key => $subvalue) { |
|
220 | + $value[$key] = \Kirki\Field\Color::sanitize($subvalue); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return $value; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
233 | 233 | * @return void |
234 | 234 | */ |
235 | - public function add_setting( $wp_customize ) {} |
|
235 | + public function add_setting($wp_customize) {} |
|
236 | 236 | |
237 | 237 | /** |
238 | 238 | * Override the parent method. No need for a control. |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
243 | 243 | * @return void |
244 | 244 | */ |
245 | - public function add_control( $wp_customize ) {} |
|
245 | + public function add_control($wp_customize) {} |
|
246 | 246 | |
247 | 247 | /** |
248 | 248 | * Adds a custom output class for typography fields. |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param array $classnames The array of classnames. |
253 | 253 | * @return array |
254 | 254 | */ |
255 | - public function output_control_classnames( $classnames ) { |
|
255 | + public function output_control_classnames($classnames) { |
|
256 | 256 | $classnames['kirki-multicolor'] = '\Kirki\Field\CSS\Multicolor'; |
257 | 257 | return $classnames; |
258 | 258 | } |
@@ -18,75 +18,75 @@ |
||
18 | 18 | */ |
19 | 19 | class Slider extends Field { |
20 | 20 | |
21 | - /** |
|
22 | - * The field type. |
|
23 | - * |
|
24 | - * @since 1.0 |
|
25 | - * @access public |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $type = 'kirki-slider'; |
|
29 | - |
|
30 | - /** |
|
31 | - * The control class-name. |
|
32 | - * |
|
33 | - * @since 1.0 |
|
34 | - * @access protected |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $control_class = '\Kirki\Control\Slider'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Whether we should register the control class for JS-templating or not. |
|
41 | - * |
|
42 | - * @since 1.0 |
|
43 | - * @access protected |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - protected $control_has_js_template = true; |
|
47 | - |
|
48 | - /** |
|
49 | - * Filter arguments before creating the setting. |
|
50 | - * |
|
51 | - * @param array $args The field arguments. |
|
52 | - * @param \WP_Customize_Manager $wp_customize The customizer instance. |
|
53 | - * |
|
54 | - * @return array $args The maybe-filtered arguments. |
|
55 | - */ |
|
56 | - public function filter_setting_args( $args, $wp_customize ) { |
|
57 | - |
|
58 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
59 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
60 | - |
|
61 | - // Set the sanitize_callback if none is defined. |
|
62 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
63 | - $args['sanitize_callback'] = function ( $value ) { |
|
64 | - return filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
65 | - }; |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - return $args; |
|
70 | - |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Filter arguments before creating the control. |
|
75 | - * |
|
76 | - * @param array $args The field arguments. |
|
77 | - * @param \WP_Customize_Manager $wp_customize The customizer instance. |
|
78 | - * |
|
79 | - * @return array $args The maybe-filtered arguments. |
|
80 | - */ |
|
81 | - public function filter_control_args( $args, $wp_customize ) { |
|
82 | - |
|
83 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
84 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
85 | - $args['type'] = 'kirki-slider'; |
|
86 | - } |
|
87 | - |
|
88 | - return $args; |
|
89 | - |
|
90 | - } |
|
21 | + /** |
|
22 | + * The field type. |
|
23 | + * |
|
24 | + * @since 1.0 |
|
25 | + * @access public |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $type = 'kirki-slider'; |
|
29 | + |
|
30 | + /** |
|
31 | + * The control class-name. |
|
32 | + * |
|
33 | + * @since 1.0 |
|
34 | + * @access protected |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $control_class = '\Kirki\Control\Slider'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Whether we should register the control class for JS-templating or not. |
|
41 | + * |
|
42 | + * @since 1.0 |
|
43 | + * @access protected |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + protected $control_has_js_template = true; |
|
47 | + |
|
48 | + /** |
|
49 | + * Filter arguments before creating the setting. |
|
50 | + * |
|
51 | + * @param array $args The field arguments. |
|
52 | + * @param \WP_Customize_Manager $wp_customize The customizer instance. |
|
53 | + * |
|
54 | + * @return array $args The maybe-filtered arguments. |
|
55 | + */ |
|
56 | + public function filter_setting_args( $args, $wp_customize ) { |
|
57 | + |
|
58 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
59 | + $args = parent::filter_setting_args( $args, $wp_customize ); |
|
60 | + |
|
61 | + // Set the sanitize_callback if none is defined. |
|
62 | + if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
63 | + $args['sanitize_callback'] = function ( $value ) { |
|
64 | + return filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
65 | + }; |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + return $args; |
|
70 | + |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Filter arguments before creating the control. |
|
75 | + * |
|
76 | + * @param array $args The field arguments. |
|
77 | + * @param \WP_Customize_Manager $wp_customize The customizer instance. |
|
78 | + * |
|
79 | + * @return array $args The maybe-filtered arguments. |
|
80 | + */ |
|
81 | + public function filter_control_args( $args, $wp_customize ) { |
|
82 | + |
|
83 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
84 | + $args = parent::filter_control_args( $args, $wp_customize ); |
|
85 | + $args['type'] = 'kirki-slider'; |
|
86 | + } |
|
87 | + |
|
88 | + return $args; |
|
89 | + |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return array $args The maybe-filtered arguments. |
55 | 55 | */ |
56 | - public function filter_setting_args( $args, $wp_customize ) { |
|
56 | + public function filter_setting_args($args, $wp_customize) { |
|
57 | 57 | |
58 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
59 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
58 | + if ($args['settings'] === $this->args['settings']) { |
|
59 | + $args = parent::filter_setting_args($args, $wp_customize); |
|
60 | 60 | |
61 | 61 | // Set the sanitize_callback if none is defined. |
62 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
63 | - $args['sanitize_callback'] = function ( $value ) { |
|
64 | - return filter_var( $value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
62 | + if (!isset($args['sanitize_callback']) || !$args['sanitize_callback']) { |
|
63 | + $args['sanitize_callback'] = function($value) { |
|
64 | + return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
65 | 65 | }; |
66 | 66 | } |
67 | 67 | } |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return array $args The maybe-filtered arguments. |
80 | 80 | */ |
81 | - public function filter_control_args( $args, $wp_customize ) { |
|
81 | + public function filter_control_args($args, $wp_customize) { |
|
82 | 82 | |
83 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
84 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
83 | + if ($args['settings'] === $this->args['settings']) { |
|
84 | + $args = parent::filter_control_args($args, $wp_customize); |
|
85 | 85 | $args['type'] = 'kirki-slider'; |
86 | 86 | } |
87 | 87 |
@@ -21,91 +21,91 @@ |
||
21 | 21 | */ |
22 | 22 | class Slider extends Base { |
23 | 23 | |
24 | - /** |
|
25 | - * The control type. |
|
26 | - * |
|
27 | - * @since 1.0 |
|
28 | - * @access public |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - public $type = 'kirki-slider'; |
|
32 | - |
|
33 | - /** |
|
34 | - * The control version. |
|
35 | - * |
|
36 | - * @since 1.0 |
|
37 | - * @access public |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public static $control_ver = '1.0.4'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Enqueue control related styles/scripts. |
|
44 | - * |
|
45 | - * @since 1.0 |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - public function enqueue() { |
|
49 | - |
|
50 | - parent::enqueue(); |
|
51 | - |
|
52 | - // Enqueue the style. |
|
53 | - wp_enqueue_style( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
54 | - |
|
55 | - // Enqueue the script. |
|
56 | - wp_enqueue_script( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-controls', 'customize-base', 'react-dom' ], self::$control_ver, false ); |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Refresh the parameters passed to the JavaScript via JSON. |
|
62 | - * |
|
63 | - * @see WP_Customize_Control::to_json() |
|
64 | - * |
|
65 | - * @since 1.0 |
|
66 | - * @access public |
|
67 | - */ |
|
68 | - public function to_json() { |
|
69 | - |
|
70 | - parent::to_json(); |
|
71 | - |
|
72 | - $this->json['choices'] = wp_parse_args( |
|
73 | - $this->json['choices'], |
|
74 | - [ |
|
75 | - 'min' => 0, |
|
76 | - 'max' => 100, |
|
77 | - 'step' => 1, |
|
78 | - ] |
|
79 | - ); |
|
80 | - |
|
81 | - if ( isset( $this->json['label'] ) ) { |
|
82 | - $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
83 | - } |
|
84 | - |
|
85 | - if ( isset( $this->json['description'] ) ) { |
|
86 | - $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
87 | - } |
|
88 | - |
|
89 | - $this->json['choices']['min'] = (float) $this->json['choices']['min']; |
|
90 | - $this->json['choices']['max'] = (float) $this->json['choices']['max']; |
|
91 | - $this->json['choices']['step'] = (float) $this->json['choices']['step']; |
|
92 | - |
|
93 | - $this->json['value'] = $this->json['value'] < $this->json['choices']['min'] ? $this->json['choices']['min'] : $this->json['value']; |
|
94 | - $this->json['value'] = $this->json['value'] > $this->json['choices']['max'] ? $this->json['choices']['max'] : $this->json['value']; |
|
95 | - $this->json['value'] = (float) $this->json['value']; |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * An Underscore (JS) template for this control's content (but not its container). |
|
101 | - * |
|
102 | - * Class variables for this control class are available in the `data` JS object; |
|
103 | - * export custom variables by overriding WP_Customize_Control::to_json(). |
|
104 | - * |
|
105 | - * @see WP_Customize_Control::print_template() |
|
106 | - * |
|
107 | - * @since 1.0 |
|
108 | - */ |
|
109 | - protected function content_template() {} |
|
24 | + /** |
|
25 | + * The control type. |
|
26 | + * |
|
27 | + * @since 1.0 |
|
28 | + * @access public |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + public $type = 'kirki-slider'; |
|
32 | + |
|
33 | + /** |
|
34 | + * The control version. |
|
35 | + * |
|
36 | + * @since 1.0 |
|
37 | + * @access public |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public static $control_ver = '1.0.4'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Enqueue control related styles/scripts. |
|
44 | + * |
|
45 | + * @since 1.0 |
|
46 | + * @access public |
|
47 | + */ |
|
48 | + public function enqueue() { |
|
49 | + |
|
50 | + parent::enqueue(); |
|
51 | + |
|
52 | + // Enqueue the style. |
|
53 | + wp_enqueue_style( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
54 | + |
|
55 | + // Enqueue the script. |
|
56 | + wp_enqueue_script( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-controls', 'customize-base', 'react-dom' ], self::$control_ver, false ); |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Refresh the parameters passed to the JavaScript via JSON. |
|
62 | + * |
|
63 | + * @see WP_Customize_Control::to_json() |
|
64 | + * |
|
65 | + * @since 1.0 |
|
66 | + * @access public |
|
67 | + */ |
|
68 | + public function to_json() { |
|
69 | + |
|
70 | + parent::to_json(); |
|
71 | + |
|
72 | + $this->json['choices'] = wp_parse_args( |
|
73 | + $this->json['choices'], |
|
74 | + [ |
|
75 | + 'min' => 0, |
|
76 | + 'max' => 100, |
|
77 | + 'step' => 1, |
|
78 | + ] |
|
79 | + ); |
|
80 | + |
|
81 | + if ( isset( $this->json['label'] ) ) { |
|
82 | + $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
83 | + } |
|
84 | + |
|
85 | + if ( isset( $this->json['description'] ) ) { |
|
86 | + $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
87 | + } |
|
88 | + |
|
89 | + $this->json['choices']['min'] = (float) $this->json['choices']['min']; |
|
90 | + $this->json['choices']['max'] = (float) $this->json['choices']['max']; |
|
91 | + $this->json['choices']['step'] = (float) $this->json['choices']['step']; |
|
92 | + |
|
93 | + $this->json['value'] = $this->json['value'] < $this->json['choices']['min'] ? $this->json['choices']['min'] : $this->json['value']; |
|
94 | + $this->json['value'] = $this->json['value'] > $this->json['choices']['max'] ? $this->json['choices']['max'] : $this->json['value']; |
|
95 | + $this->json['value'] = (float) $this->json['value']; |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * An Underscore (JS) template for this control's content (but not its container). |
|
101 | + * |
|
102 | + * Class variables for this control class are available in the `data` JS object; |
|
103 | + * export custom variables by overriding WP_Customize_Control::to_json(). |
|
104 | + * |
|
105 | + * @see WP_Customize_Control::print_template() |
|
106 | + * |
|
107 | + * @since 1.0 |
|
108 | + */ |
|
109 | + protected function content_template() {} |
|
110 | 110 | |
111 | 111 | } |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | parent::enqueue(); |
51 | 51 | |
52 | 52 | // Enqueue the style. |
53 | - wp_enqueue_style( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
53 | + wp_enqueue_style('kirki-control-slider', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.css'), [], self::$control_ver); |
|
54 | 54 | |
55 | 55 | // Enqueue the script. |
56 | - wp_enqueue_script( 'kirki-control-slider', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-controls', 'customize-base', 'react-dom' ], self::$control_ver, false ); |
|
56 | + wp_enqueue_script('kirki-control-slider', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.js'), ['jquery', 'customize-controls', 'customize-base', 'react-dom'], self::$control_ver, false); |
|
57 | 57 | |
58 | 58 | } |
59 | 59 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | ] |
79 | 79 | ); |
80 | 80 | |
81 | - if ( isset( $this->json['label'] ) ) { |
|
82 | - $this->json['label'] = html_entity_decode( $this->json['label'] ); |
|
81 | + if (isset($this->json['label'])) { |
|
82 | + $this->json['label'] = html_entity_decode($this->json['label']); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( isset( $this->json['description'] ) ) { |
|
86 | - $this->json['description'] = html_entity_decode( $this->json['description'] ); |
|
85 | + if (isset($this->json['description'])) { |
|
86 | + $this->json['description'] = html_entity_decode($this->json['description']); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $this->json['choices']['min'] = (float) $this->json['choices']['min']; |
@@ -14,9 +14,9 @@ |
||
14 | 14 | } |
15 | 15 | if (!ini_get('display_errors')) { |
16 | 16 | if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
17 | - fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); |
|
17 | + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL . PHP_EOL); |
|
18 | 18 | } elseif (!headers_sent()) { |
19 | - echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; |
|
19 | + echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace('You are running ' . PHP_VERSION . '.', '', implode(PHP_EOL, $issues)) . PHP_EOL . PHP_EOL; |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | trigger_error( |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | if (null !== $this->apcuPrefix) { |
453 | - $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
453 | + $file = apcu_fetch($this->apcuPrefix . $class, $hit); |
|
454 | 454 | if ($hit) { |
455 | 455 | return $file; |
456 | 456 | } |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | } |
465 | 465 | |
466 | 466 | if (null !== $this->apcuPrefix) { |
467 | - apcu_add($this->apcuPrefix.$class, $file); |
|
467 | + apcu_add($this->apcuPrefix . $class, $file); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | if (false === $file) { |
@@ -325,9 +325,9 @@ |
||
325 | 325 | foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { |
326 | 326 | if (isset(self::$installedByVendor[$vendorDir])) { |
327 | 327 | $installed[] = self::$installedByVendor[$vendorDir]; |
328 | - } elseif (is_file($vendorDir.'/composer/installed.php')) { |
|
329 | - $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; |
|
330 | - if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { |
|
328 | + } elseif (is_file($vendorDir . '/composer/installed.php')) { |
|
329 | + $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir . '/composer/installed.php'; |
|
330 | + if (null === self::$installed && strtr($vendorDir . '/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { |
|
331 | 331 | self::$installed = $installed[count($installed) - 1]; |
332 | 332 | } |
333 | 333 | } |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitc56aa391ac498061f8d648878e0e6144 |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'K' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'Kirki\\Util\\' => 11, |
13 | 13 | 'Kirki\\Settings\\' => 15, |
14 | 14 | 'Kirki\\Module\\' => 13, |
@@ -19,27 +19,27 @@ discard block |
||
19 | 19 | 'Kirki\\' => 6, |
20 | 20 | ), |
21 | 21 | 'D' => |
22 | - array ( |
|
22 | + array( |
|
23 | 23 | 'Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\' => 55, |
24 | 24 | ), |
25 | 25 | 'C' => |
26 | - array ( |
|
26 | + array( |
|
27 | 27 | 'Composer\\Installers\\' => 20, |
28 | 28 | ), |
29 | 29 | ); |
30 | 30 | |
31 | - public static $prefixDirsPsr4 = array ( |
|
31 | + public static $prefixDirsPsr4 = array( |
|
32 | 32 | 'Kirki\\Util\\' => |
33 | - array ( |
|
33 | + array( |
|
34 | 34 | 0 => __DIR__ . '/..' . '/kirki-framework/control-dashicons/src/Util', |
35 | 35 | 1 => __DIR__ . '/..' . '/kirki-framework/util/src', |
36 | 36 | ), |
37 | 37 | 'Kirki\\Settings\\' => |
38 | - array ( |
|
38 | + array( |
|
39 | 39 | 0 => __DIR__ . '/..' . '/kirki-framework/control-repeater/src/Settings', |
40 | 40 | ), |
41 | 41 | 'Kirki\\Module\\' => |
42 | - array ( |
|
42 | + array( |
|
43 | 43 | 0 => __DIR__ . '/..' . '/kirki-framework/module-css/src', |
44 | 44 | 1 => __DIR__ . '/..' . '/kirki-framework/module-editor-styles/src', |
45 | 45 | 2 => __DIR__ . '/..' . '/kirki-framework/module-field-dependencies/src', |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 8 => __DIR__ . '/..' . '/kirki-framework/module-webfonts/src', |
52 | 52 | ), |
53 | 53 | 'Kirki\\Field\\' => |
54 | - array ( |
|
54 | + array( |
|
55 | 55 | 0 => __DIR__ . '/..' . '/kirki-framework/control-checkbox/src/Field', |
56 | 56 | 1 => __DIR__ . '/..' . '/kirki-framework/control-code/src/Field', |
57 | 57 | 2 => __DIR__ . '/..' . '/kirki-framework/control-color/src/Field', |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | 25 => __DIR__ . '/..' . '/kirki-framework/field-typography/src/Field', |
81 | 81 | ), |
82 | 82 | 'Kirki\\Data\\' => |
83 | - array ( |
|
83 | + array( |
|
84 | 84 | 0 => __DIR__ . '/..' . '/kirki-framework/data-option/src', |
85 | 85 | ), |
86 | 86 | 'Kirki\\Control\\' => |
87 | - array ( |
|
87 | + array( |
|
88 | 88 | 0 => __DIR__ . '/..' . '/kirki-framework/control-base/src/Control', |
89 | 89 | 1 => __DIR__ . '/..' . '/kirki-framework/control-checkbox/src/Control', |
90 | 90 | 2 => __DIR__ . '/..' . '/kirki-framework/control-code/src/Control', |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | 24 => __DIR__ . '/..' . '/kirki-framework/field-typography/src/Control', |
113 | 113 | ), |
114 | 114 | 'Kirki\\Compatibility\\' => |
115 | - array ( |
|
115 | + array( |
|
116 | 116 | 0 => __DIR__ . '/..' . '/kirki-framework/compatibility/src', |
117 | 117 | ), |
118 | 118 | 'Kirki\\' => |
119 | - array ( |
|
119 | + array( |
|
120 | 120 | 0 => __DIR__ . '/..' . '/kirki-framework/field/src', |
121 | 121 | 1 => __DIR__ . '/..' . '/kirki-framework/googlefonts/src', |
122 | 122 | 2 => __DIR__ . '/..' . '/kirki-framework/l10n/src', |
@@ -125,22 +125,22 @@ discard block |
||
125 | 125 | 5 => __DIR__ . '/..' . '/kirki-framework/url-getter/src', |
126 | 126 | ), |
127 | 127 | 'Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\' => |
128 | - array ( |
|
128 | + array( |
|
129 | 129 | 0 => __DIR__ . '/..' . '/dealerdirect/phpcodesniffer-composer-installer/src', |
130 | 130 | ), |
131 | 131 | 'Composer\\Installers\\' => |
132 | - array ( |
|
132 | + array( |
|
133 | 133 | 0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers', |
134 | 134 | ), |
135 | 135 | ); |
136 | 136 | |
137 | - public static $classMap = array ( |
|
137 | + public static $classMap = array( |
|
138 | 138 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
139 | 139 | ); |
140 | 140 | |
141 | 141 | public static function getInitializer(ClassLoader $loader) |
142 | 142 | { |
143 | - return \Closure::bind(function () use ($loader) { |
|
143 | + return \Closure::bind(function() use ($loader) { |
|
144 | 144 | $loader->prefixLengthsPsr4 = ComposerStaticInitc56aa391ac498061f8d648878e0e6144::$prefixLengthsPsr4; |
145 | 145 | $loader->prefixDirsPsr4 = ComposerStaticInitc56aa391ac498061f8d648878e0e6144::$prefixDirsPsr4; |
146 | 146 | $loader->classMap = ComposerStaticInitc56aa391ac498061f8d648878e0e6144::$classMap; |