Completed
Push — develop ( 87ee00...da5642 )
by Aristeides
16:37 queued 10:32
created
modules/postmessage/class-kirki-modules-postmessage.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		wp_enqueue_script( 'kirki_auto_postmessage', trailingslashit( Kirki::$url ) . 'modules/postmessage/postmessage.js', array( 'jquery', 'customize-preview' ), KIRKI_VERSION, true );
75 75
 		$fields = Kirki::$fields;
76 76
 		foreach ( $fields as $field ) {
77
-			if ( isset( $field['transport'] ) && 'postMessage' === $field['transport'] && isset( $field['js_vars'] ) && ! empty( $field['js_vars'] ) && is_array( $field['js_vars'] ) && isset( $field['settings'] ) ) {
77
+			if ( isset( $field[ 'transport' ] ) && 'postMessage' === $field[ 'transport' ] && isset( $field[ 'js_vars' ] ) && ! empty( $field[ 'js_vars' ] ) && is_array( $field[ 'js_vars' ] ) && isset( $field[ 'settings' ] ) ) {
78 78
 				$this->script .= $this->script( $field );
79 79
 			}
80 80
 		}
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 * @param array $args The arguments.
91 91
 	 */
92 92
 	protected function script( $args ) {
93
-		$script = 'wp.customize(\'' . $args['settings'] . '\',function(value){value.bind(function(newval){';
93
+		$script = 'wp.customize(\'' . $args[ 'settings' ] . '\',function(value){value.bind(function(newval){';
94 94
 
95 95
 		$add_css = false;
96
-		foreach ( $args['js_vars'] as $js_var ) {
97
-			if ( ! isset( $js_var['function'] ) || 'html' !== $js_var['function'] ) {
96
+		foreach ( $args[ 'js_vars' ] as $js_var ) {
97
+			if ( ! isset( $js_var[ 'function' ] ) || 'html' !== $js_var[ 'function' ] ) {
98 98
 				$add_css = true;
99 99
 			}
100
-			if ( isset( $js_var['context'] ) && ! in_array( 'front', $js_var['context'] ) ) {
100
+			if ( isset( $js_var[ 'context' ] ) && ! in_array( 'front', $js_var[ 'context' ] ) ) {
101 101
 				$add_css = false;
102 102
 			}
103 103
 		}
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 
107 107
 			// append unique style tag if not exist
108 108
 			// The style ID.
109
-			$style_id = 'kirki-postmessage-' . str_replace( array( '[', ']' ), '', $args['settings'] );
109
+			$style_id = 'kirki-postmessage-' . str_replace( array( '[', ']' ), '', $args[ 'settings' ] );
110 110
 			$script  .= 'if(null===document.getElementById(\'' . $style_id . '\')||\'undefined\'===typeof document.getElementById(\'' . $style_id . '\')){jQuery(\'head\').append(\'<style id="' . $style_id . '"></style>\');}';
111 111
 		}
112 112
 
@@ -118,48 +118,48 @@  discard block
 block discarded – undo
118 118
 		);
119 119
 
120 120
 		// Loop through the js_vars and generate the script.
121
-		foreach ( $args['js_vars'] as $key => $js_var ) {
121
+		foreach ( $args[ 'js_vars' ] as $key => $js_var ) {
122 122
 
123 123
 			// Skip styles if "exclude" is defined and value is excluded.
124
-			if ( isset( $js_var['exclude'] ) ) {
125
-				$js_var['exclude'] = (array) $js_var['exclude'];
124
+			if ( isset( $js_var[ 'exclude' ] ) ) {
125
+				$js_var[ 'exclude' ] = (array) $js_var[ 'exclude' ];
126 126
 				$script           .= 'exclude=false;';
127
-				foreach ( $js_var['exclude'] as $exclussion ) {
127
+				foreach ( $js_var[ 'exclude' ] as $exclussion ) {
128 128
 					$script .= "if(newval=='{$exclussion}'||(''==='{$exclussion}'&&_.isObject(newval)&&_.isEmpty(newval))){exclude=true;}";
129 129
 				}
130 130
 			}
131
-			if ( isset( $js_var['element'] ) ) {
131
+			if ( isset( $js_var[ 'element' ] ) ) {
132 132
 
133 133
 				// Array to string.
134
-				if ( is_array( $js_var['element'] ) ) {
135
-					$js_var['element'] = implode( ',', $js_var['element'] );
134
+				if ( is_array( $js_var[ 'element' ] ) ) {
135
+					$js_var[ 'element' ] = implode( ',', $js_var[ 'element' ] );
136 136
 				}
137 137
 
138 138
 				// Replace single quotes with double quotes to avoid issues with the compiled JS.
139
-				$js_var['element'] = str_replace( '\'', '"', $js_var['element'] );
139
+				$js_var[ 'element' ] = str_replace( '\'', '"', $js_var[ 'element' ] );
140 140
 			}
141
-			if ( isset( $js_var['function'] ) && 'html' === $js_var['function'] ) {
141
+			if ( isset( $js_var[ 'function' ] ) && 'html' === $js_var[ 'function' ] ) {
142 142
 				$script .= $this->script_html_var( $js_var );
143 143
 				continue;
144 144
 			}
145
-			$js_var['index_key'] = $key;
145
+			$js_var[ 'index_key' ] = $key;
146 146
 			$callback            = $this->get_callback( $args );
147 147
 			if ( is_callable( $callback ) ) {
148
-				$field['scripts'][ $key ] = call_user_func_array( $callback, array( $js_var, $args ) );
148
+				$field[ 'scripts' ][ $key ] = call_user_func_array( $callback, array( $js_var, $args ) );
149 149
 				continue;
150 150
 			}
151
-			$field['scripts'][ $key ] = $this->script_var( $js_var );
151
+			$field[ 'scripts' ][ $key ] = $this->script_var( $js_var );
152 152
 		}
153 153
 		$combo_extra_script = '';
154 154
 		$combo_css_script   = '';
155
-		foreach ( $field['scripts'] as $script_array ) {
156
-			$combo_extra_script .= $script_array['script'];
157
-			$combo_css_script   .= ( 'css' !== $combo_css_script ) ? $script_array['css'] : '';
155
+		foreach ( $field[ 'scripts' ] as $script_array ) {
156
+			$combo_extra_script .= $script_array[ 'script' ];
157
+			$combo_css_script   .= ( 'css' !== $combo_css_script ) ? $script_array[ 'css' ] : '';
158 158
 		}
159 159
 		$text = ( 'css' === $combo_css_script ) ? 'css' : '\'' . $combo_css_script . '\'';
160 160
 
161 161
 		$script .= $combo_extra_script . "var cssContent={$text};";
162
-		if ( isset( $js_var['exclude'] ) ) {
162
+		if ( isset( $js_var[ 'exclude' ] ) ) {
163 163
 			$script .= 'if(true===exclude){cssContent="";}';
164 164
 		}
165 165
 		if ( $add_css ) {
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
 	 * @param array $args  The arguments for this js_var.
178 178
 	 */
179 179
 	protected function script_html_var( $args ) {
180
-		$script = ( isset( $args['choice'] ) ) ? "newval=newval['{$args['choice']}'];" : '';
180
+		$script = ( isset( $args[ 'choice' ] ) ) ? "newval=newval['{$args[ 'choice' ]}'];" : '';
181 181
 
182 182
 		// Apply the value_pattern.
183
-		if ( isset( $args['value_pattern'] ) && '' !== $args['value_pattern'] ) {
183
+		if ( isset( $args[ 'value_pattern' ] ) && '' !== $args[ 'value_pattern' ] ) {
184 184
 			$script .= $this->value_pattern_replacements( 'newval', $args );
185 185
 		}
186 186
 
187
-		if ( isset( $args['attr'] ) ) {
188
-			$script .= "jQuery('{$args['element']}').attr('{$args['attr']}',newval);";
187
+		if ( isset( $args[ 'attr' ] ) ) {
188
+			$script .= "jQuery('{$args[ 'element' ]}').attr('{$args[ 'attr' ]}',newval);";
189 189
 			return $script;
190 190
 		}
191
-		$script .= "jQuery('{$args['element']}').html(newval);";
191
+		$script .= "jQuery('{$args[ 'element' ]}').html(newval);";
192 192
 		return $script;
193 193
 	}
194 194
 
@@ -203,34 +203,34 @@  discard block
 block discarded – undo
203 203
 		$script          = '';
204 204
 		$property_script = '';
205 205
 
206
-		$value_key        = 'newval' . $args['index_key'];
206
+		$value_key        = 'newval' . $args[ 'index_key' ];
207 207
 		$property_script .= $value_key . '=newval;';
208 208
 
209 209
 		$args = $this->get_args( $args );
210 210
 
211 211
 		// Apply callback to the value if a callback is defined.
212
-		if ( ! empty( $args['js_callback'] ) && is_array( $args['js_callback'] ) && isset( $args['js_callback'][0] ) && ! empty( $args['js_callback'][0] ) ) {
213
-			$script .= $value_key . '=' . $args['js_callback'][0] . '(' . $value_key . ',' . $args['js_callback'][1] . ');';
212
+		if ( ! empty( $args[ 'js_callback' ] ) && is_array( $args[ 'js_callback' ] ) && isset( $args[ 'js_callback' ][ 0 ] ) && ! empty( $args[ 'js_callback' ][ 0 ] ) ) {
213
+			$script .= $value_key . '=' . $args[ 'js_callback' ][ 0 ] . '(' . $value_key . ',' . $args[ 'js_callback' ][ 1 ] . ');';
214 214
 		}
215 215
 
216 216
 		// Apply the value_pattern.
217
-		if ( '' !== $args['value_pattern'] ) {
217
+		if ( '' !== $args[ 'value_pattern' ] ) {
218 218
 			$script .= $this->value_pattern_replacements( $value_key, $args );
219 219
 		}
220 220
 
221 221
 		// Tweak to add url() for background-images.
222
-		if ( 'background-image' === $args['property'] && ( ! isset( $args['value_pattern'] ) || false === strpos( $args['value_pattern'], 'gradient' ) ) ) {
222
+		if ( 'background-image' === $args[ 'property' ] && ( ! isset( $args[ 'value_pattern' ] ) || false === strpos( $args[ 'value_pattern' ], 'gradient' ) ) ) {
223 223
 			$script .= 'if(-1===' . $value_key . '.indexOf(\'url(\')){' . $value_key . '=\'url("\'+' . $value_key . '+\'")\';}';
224 224
 		}
225 225
 
226 226
 		// Apply prefix.
227 227
 		$value = $value_key;
228
-		if ( '' !== $args['prefix'] ) {
229
-			$value = "'" . $args['prefix'] . "'+" . $value_key;
228
+		if ( '' !== $args[ 'prefix' ] ) {
229
+			$value = "'" . $args[ 'prefix' ] . "'+" . $value_key;
230 230
 		}
231
-		$css = $args['element'] . '{' . $args['property'] . ':\'+' . $value . '+\'' . $args['units'] . $args['suffix'] . ';}';
232
-		if ( isset( $args['media_query'] ) ) {
233
-			$css = $args['media_query'] . '{' . $css . '}';
231
+		$css = $args[ 'element' ] . '{' . $args[ 'property' ] . ':\'+' . $value . '+\'' . $args[ 'units' ] . $args[ 'suffix' ] . ';}';
232
+		if ( isset( $args[ 'media_query' ] ) ) {
233
+			$css = $args[ 'media_query' ] . '{' . $css . '}';
234 234
 		}
235 235
 		return array(
236 236
 			'script' => $property_script . $script,
@@ -246,42 +246,42 @@  discard block
 block discarded – undo
246 246
 	 * @param array $args  The arguments for this js_var.
247 247
 	 */
248 248
 	protected function script_var_array( $args ) {
249
-		$script          = ( 0 === $args['index_key'] ) ? 'css=\'\';' : '';
249
+		$script          = ( 0 === $args[ 'index_key' ] ) ? 'css=\'\';' : '';
250 250
 		$property_script = '';
251 251
 
252 252
 		// Define choice.
253
-		$choice = ( isset( $args['choice'] ) && '' !== $args['choice'] ) ? $args['choice'] : '';
253
+		$choice = ( isset( $args[ 'choice' ] ) && '' !== $args[ 'choice' ] ) ? $args[ 'choice' ] : '';
254 254
 
255
-		$value_key        = 'newval' . $args['index_key'];
255
+		$value_key        = 'newval' . $args[ 'index_key' ];
256 256
 		$property_script .= $value_key . '=newval;';
257 257
 
258 258
 		$args = $this->get_args( $args );
259 259
 
260 260
 		// Apply callback to the value if a callback is defined.
261
-		if ( ! empty( $args['js_callback'] ) && is_array( $args['js_callback'] ) && isset( $args['js_callback'][0] ) && ! empty( $args['js_callback'][0] ) ) {
262
-			$script .= $value_key . '=' . $args['js_callback'][0] . '(' . $value_key . ',' . $args['js_callback'][1] . ');';
261
+		if ( ! empty( $args[ 'js_callback' ] ) && is_array( $args[ 'js_callback' ] ) && isset( $args[ 'js_callback' ][ 0 ] ) && ! empty( $args[ 'js_callback' ][ 0 ] ) ) {
262
+			$script .= $value_key . '=' . $args[ 'js_callback' ][ 0 ] . '(' . $value_key . ',' . $args[ 'js_callback' ][ 1 ] . ');';
263 263
 		}
264 264
 		$script .= '_.each(' . $value_key . ', function(subValue,subKey){';
265 265
 
266 266
 		// Apply the value_pattern.
267
-		if ( '' !== $args['value_pattern'] ) {
267
+		if ( '' !== $args[ 'value_pattern' ] ) {
268 268
 			$script .= $this->value_pattern_replacements( 'subValue', $args );
269 269
 		}
270 270
 
271 271
 		// Tweak to add url() for background-images.
272 272
 		if ( '' === $choice || 'background-image' === $choice ) {
273
-			$script .= 'if(\'background-image\'===\'' . $args['property'] . '\'||\'background-image\'===subKey){if(-1===subValue.indexOf(\'url(\')){subValue=\'url("\'+subValue+\'")\';}}';
273
+			$script .= 'if(\'background-image\'===\'' . $args[ 'property' ] . '\'||\'background-image\'===subKey){if(-1===subValue.indexOf(\'url(\')){subValue=\'url("\'+subValue+\'")\';}}';
274 274
 		}
275 275
 
276 276
 		// Apply prefix.
277 277
 		$value = $value_key;
278
-		if ( '' !== $args['prefix'] ) {
279
-			$value = '\'' . $args['prefix'] . '\'+subValue';
278
+		if ( '' !== $args[ 'prefix' ] ) {
279
+			$value = '\'' . $args[ 'prefix' ] . '\'+subValue';
280 280
 		}
281 281
 
282 282
 		// Mostly used for padding, margin & position properties.
283 283
 		$direction_script  = 'if(_.contains([\'top\',\'bottom\',\'left\',\'right\'],subKey)){';
284
-		$direction_script .= 'css+=\'' . $args['element'] . '{' . $args['property'] . '-\'+subKey+\':\'+subValue+\'' . $args['units'] . $args['suffix'] . ';}\';}';
284
+		$direction_script .= 'css+=\'' . $args[ 'element' ] . '{' . $args[ 'property' ] . '-\'+subKey+\':\'+subValue+\'' . $args[ 'units' ] . $args[ 'suffix' ] . ';}\';}';
285 285
 
286 286
 		// Allows us to apply this just for a specific choice in the array of the values.
287 287
 		if ( '' !== $choice ) {
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 			// The script.
291 291
 			$script .= 'if(\'' . $choice . '\'===subKey){';
292 292
 			$script .= ( $choice_is_direction ) ? $direction_script . 'else{' : '';
293
-			$script .= 'css+=\'' . $args['element'] . '{' . $args['property'] . ':\'+subValue+\';}\';';
293
+			$script .= 'css+=\'' . $args[ 'element' ] . '{' . $args[ 'property' ] . ':\'+subValue+\';}\';';
294 294
 			$script .= ( $choice_is_direction ) ? '}' : '';
295 295
 			$script .= '}';
296 296
 		} else {
297 297
 
298 298
 			// This is where most object-based fields will go.
299
-			$script .= $direction_script . 'else{css+=\'' . $args['element'] . '{\'+subKey+\':\'+subValue+\'' . $args['units'] . $args['suffix'] . ';}\';}';
299
+			$script .= $direction_script . 'else{css+=\'' . $args[ 'element' ] . '{\'+subKey+\':\'+subValue+\'' . $args[ 'units' ] . $args[ 'suffix' ] . ';}\';}';
300 300
 		}
301 301
 		$script .= '});';
302 302
 
303
-		if ( isset( $args['media_query'] ) ) {
304
-			$script .= 'css=\'' . $args['media_query'] . '{\'+css+\'}\';';
303
+		if ( isset( $args[ 'media_query' ] ) ) {
304
+			$script .= 'css=\'' . $args[ 'media_query' ] . '{\'+css+\'}\';';
305 305
 		}
306 306
 
307 307
 		return array(
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		$webfont_loader = 'sc=\'a\';jQuery(\'head\').append(sc.replace(\'a\',\'<\')+\'script>if(!_.isUndefined(WebFont)&&fontFamily){WebFont.load({google:{families:["\'+fontFamily.replace( /\"/g, \'&quot;\' )+\':\'+variant+\'cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai"]}});}\'+sc.replace(\'a\',\'<\')+\'/script>\');';
330 330
 
331 331
 		// Add the css.
332
-		$css_build_array  = array(
332
+		$css_build_array = array(
333 333
 			'font-family'     => 'fontFamily',
334 334
 			'font-size'       => 'fontSize',
335 335
 			'line-height'     => 'lineHeight',
@@ -342,41 +342,41 @@  discard block
 block discarded – undo
342 342
 			'font-weight'     => 'fontWeight',
343 343
 			'font-style'      => 'fontStyle',
344 344
 		);
345
-		$choice_condition = ( isset( $args['choice'] ) && '' !== $args['choice'] && isset( $css_build_array[ $args['choice'] ] ) );
345
+		$choice_condition = ( isset( $args[ 'choice' ] ) && '' !== $args[ 'choice' ] && isset( $css_build_array[ $args[ 'choice' ] ] ) );
346 346
 		$script          .= ( ! $choice_condition ) ? $webfont_loader : '';
347 347
 		foreach ( $css_build_array as $property => $var ) {
348
-			if ( $choice_condition && $property !== $args['choice'] ) {
348
+			if ( $choice_condition && $property !== $args[ 'choice' ] ) {
349 349
 				continue;
350 350
 			}
351 351
 			// Fixes https://github.com/aristath/kirki/issues/1436.
352
-			if ( ! isset( $field['default'] ) || (
353
-				( 'font-family' === $property && ! isset( $field['default']['font-family'] ) ) ||
354
-				( 'font-size' === $property && ! isset( $field['default']['font-size'] ) ) ||
355
-				( 'line-height' === $property && ! isset( $field['default']['line-height'] ) ) ||
356
-				( 'letter-spacing' === $property && ! isset( $field['default']['letter-spacing'] ) ) ||
357
-				( 'word-spacing' === $property && ! isset( $field['default']['word-spacing'] ) ) ||
358
-				( 'text-align' === $property && ! isset( $field['default']['text-align'] ) ) ||
359
-				( 'text-transform' === $property && ! isset( $field['default']['text-transform'] ) ) ||
360
-				( 'text-decoration' === $property && ! isset( $field['default']['text-decoration'] ) ) ||
361
-				( 'color' === $property && ! isset( $field['default']['color'] ) ) ||
362
-				( 'font-weight' === $property && ! isset( $field['default']['variant'] ) && ! isset( $field['default']['font-weight'] ) ) ||
363
-				( 'font-style' === $property && ! isset( $field['default']['variant'] ) && ! isset( $field['default']['font-style'] ) )
352
+			if ( ! isset( $field[ 'default' ] ) || (
353
+				( 'font-family' === $property && ! isset( $field[ 'default' ][ 'font-family' ] ) ) ||
354
+				( 'font-size' === $property && ! isset( $field[ 'default' ][ 'font-size' ] ) ) ||
355
+				( 'line-height' === $property && ! isset( $field[ 'default' ][ 'line-height' ] ) ) ||
356
+				( 'letter-spacing' === $property && ! isset( $field[ 'default' ][ 'letter-spacing' ] ) ) ||
357
+				( 'word-spacing' === $property && ! isset( $field[ 'default' ][ 'word-spacing' ] ) ) ||
358
+				( 'text-align' === $property && ! isset( $field[ 'default' ][ 'text-align' ] ) ) ||
359
+				( 'text-transform' === $property && ! isset( $field[ 'default' ][ 'text-transform' ] ) ) ||
360
+				( 'text-decoration' === $property && ! isset( $field[ 'default' ][ 'text-decoration' ] ) ) ||
361
+				( 'color' === $property && ! isset( $field[ 'default' ][ 'color' ] ) ) ||
362
+				( 'font-weight' === $property && ! isset( $field[ 'default' ][ 'variant' ] ) && ! isset( $field[ 'default' ][ 'font-weight' ] ) ) ||
363
+				( 'font-style' === $property && ! isset( $field[ 'default' ][ 'variant' ] ) && ! isset( $field[ 'default' ][ 'font-style' ] ) )
364 364
 				) ) {
365 365
 				continue;
366 366
 			}
367
-			$script .= ( $choice_condition && 'font-family' === $args['choice'] ) ? $webfont_loader : '';
367
+			$script .= ( $choice_condition && 'font-family' === $args[ 'choice' ] ) ? $webfont_loader : '';
368 368
 
369
-			if ( 'font-family' === $property || ( isset( $args['choice'] ) && 'font-family' === $args['choice'] ) ) {
369
+			if ( 'font-family' === $property || ( isset( $args[ 'choice' ] ) && 'font-family' === $args[ 'choice' ] ) ) {
370 370
 				$css .= 'fontFamilyCSS=fontFamily;if(0<fontFamily.indexOf(\' \')&&-1===fontFamily.indexOf(\'"\')){fontFamilyCSS=\'"\'+fontFamily+\'"\';}';
371 371
 				$var  = 'fontFamilyCSS';
372 372
 			}
373
-			$var  = ( ( empty( $args['prefix'] ) ) ? '' : '\'' . $args['prefix'] . '\'+' ) . $var . ( ( empty( $args['units'] ) ) ? '' : '+\'' . $args['units'] . '\'' ) . ( ( empty( $args['suffix'] ) ) ? '' : '+\'' . $args['suffix'] . '\'' );
374
-			$css .= 'css+=(\'\'!==' . $var . ')?\'' . $args['element'] . '\'+\'{' . $property . ':\'+' . $var . '+\';}\':\'\';';
373
+			$var  = ( ( empty( $args[ 'prefix' ] ) ) ? '' : '\'' . $args[ 'prefix' ] . '\'+' ) . $var . ( ( empty( $args[ 'units' ] ) ) ? '' : '+\'' . $args[ 'units' ] . '\'' ) . ( ( empty( $args[ 'suffix' ] ) ) ? '' : '+\'' . $args[ 'suffix' ] . '\'' );
374
+			$css .= 'css+=(\'\'!==' . $var . ')?\'' . $args[ 'element' ] . '\'+\'{' . $property . ':\'+' . $var . '+\';}\':\'\';';
375 375
 		}
376 376
 
377 377
 		$script .= $css;
378
-		if ( isset( $args['media_query'] ) ) {
379
-			$script .= 'css=\'' . $args['media_query'] . '{\'+css+\'}\';';
378
+		if ( isset( $args[ 'media_query' ] ) ) {
379
+			$script .= 'css=\'' . $args[ 'media_query' ] . '{\'+css+\'}\';';
380 380
 		}
381 381
 		return array(
382 382
 			'script' => $script,
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	protected function script_var_image( $args ) {
395 395
 		$return = $this->script_var( $args );
396 396
 		return array(
397
-			'script' => 'newval=(!_.isUndefined(newval.url))?newval.url:newval;' . $return['script'],
398
-			'css'    => $return['css'],
397
+			'script' => 'newval=(!_.isUndefined(newval.url))?newval.url:newval;' . $return[ 'script' ],
398
+			'css'    => $return[ 'css' ],
399 399
 		);
400 400
 	}
401 401
 
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 */
410 410
 	private function before_script( $args ) {
411 411
 		$script = '';
412
-		if ( isset( $args['type'] ) ) {
413
-			switch ( $args['type'] ) {
412
+		if ( isset( $args[ 'type' ] ) ) {
413
+			switch ( $args[ 'type' ] ) {
414 414
 				case 'kirki-typography':
415 415
 					$script .= 'fontFamily=(_.isUndefined(newval[\'font-family\']))?\'\':newval[\'font-family\'];variant=(_.isUndefined(newval.variant))?\'400\':newval.variant;fontSize=(_.isUndefined(newval[\'font-size\']))?\'\':newval[\'font-size\'];lineHeight=(_.isUndefined(newval[\'line-height\']))?\'\':newval[\'line-height\'];letterSpacing=(_.isUndefined(newval[\'letter-spacing\']))?\'\':newval[\'letter-spacing\'];wordSpacing=(_.isUndefined(newval[\'word-spacing\']))?\'\':newval[\'word-spacing\'];textAlign=(_.isUndefined(newval[\'text-align\']))?\'\':newval[\'text-align\'];textTransform=(_.isUndefined(newval[\'text-transform\']))?\'\':newval[\'text-transform\'];textDecoration=(_.isUndefined(newval[\'text-decoration\']))?\'\':newval[\'text-decoration\'];color=(_.isUndefined(newval.color))?\'\':newval.color;fw=(!_.isString(newval.variant))?\'400\':newval.variant.match(/\d/g);fontWeight=(!_.isObject(fw))?400:fw.join(\'\');fontStyle=(variant&&-1!==variant.indexOf(\'italic\'))?\'italic\':\'normal\';css=\'\';';
416 416
 					break;
@@ -443,17 +443,17 @@  discard block
 block discarded – undo
443 443
 		);
444 444
 
445 445
 		// Element should be a string.
446
-		if ( is_array( $args['element'] ) ) {
447
-			$args['element'] = implode( ',', $args['element'] );
446
+		if ( is_array( $args[ 'element' ] ) ) {
447
+			$args[ 'element' ] = implode( ',', $args[ 'element' ] );
448 448
 		}
449 449
 
450 450
 		// Make sure arguments that are passed-on to callbacks are strings.
451
-		if ( is_array( $args['js_callback'] ) && isset( $args['js_callback'][1] ) && is_array( $args['js_callback'][1] ) ) {
452
-			$args['js_callback'][1] = wp_json_encode( $args['js_callback'][1] );
451
+		if ( is_array( $args[ 'js_callback' ] ) && isset( $args[ 'js_callback' ][ 1 ] ) && is_array( $args[ 'js_callback' ][ 1 ] ) ) {
452
+			$args[ 'js_callback' ][ 1 ] = wp_json_encode( $args[ 'js_callback' ][ 1 ] );
453 453
 		}
454 454
 
455
-		if ( ! isset( $args['js_callback'][1] ) ) {
456
-			$args['js_callback'][1] = '';
455
+		if ( ! isset( $args[ 'js_callback' ][ 1 ] ) ) {
456
+			$args[ 'js_callback' ][ 1 ] = '';
457 457
 		}
458 458
 		return $args;
459 459
 	}
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
 	private function value_pattern_replacements( $value, $js_vars ) {
471 471
 		$script = '';
472 472
 		$alias  = $value;
473
-		if ( ! isset( $js_vars['value_pattern'] ) ) {
473
+		if ( ! isset( $js_vars[ 'value_pattern' ] ) ) {
474 474
 			return $value;
475 475
 		}
476
-		$value = $js_vars['value_pattern'];
477
-		if ( isset( $js_vars['pattern_replace'] ) ) {
476
+		$value = $js_vars[ 'value_pattern' ];
477
+		if ( isset( $js_vars[ 'pattern_replace' ] ) ) {
478 478
 			$script .= 'settings=window.wp.customize.get();';
479
-			foreach ( $js_vars['pattern_replace'] as $search => $replace ) {
479
+			foreach ( $js_vars[ 'pattern_replace' ] as $search => $replace ) {
480 480
 				$replace = '\'+settings["' . $replace . '"]+\'';
481
-				$value   = str_replace( $search, $replace, $js_vars['value_pattern'] );
481
+				$value   = str_replace( $search, $replace, $js_vars[ 'value_pattern' ] );
482 482
 				$value   = trim( $value, '+' );
483 483
 			}
484 484
 		}
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	 * @return string|array A callable function or method.
498 498
 	 */
499 499
 	protected function get_callback( $args ) {
500
-		switch ( $args['type'] ) {
500
+		switch ( $args[ 'type' ] ) {
501 501
 			case 'kirki-background':
502 502
 			case 'kirki-dimensions':
503 503
 			case 'kirki-multicolor':
Please login to merge, or discard this patch.
modules/css/class-kirki-output.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @return string|array
82 82
 	 */
83 83
 	protected function apply_sanitize_callback( $output, $value ) {
84
-		if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) {
84
+		if ( isset( $output[ 'sanitize_callback' ] ) && null !== $output[ 'sanitize_callback' ] ) {
85 85
 
86 86
 			// If the sanitize_callback is invalid, return the value.
87
-			if ( ! is_callable( $output['sanitize_callback'] ) ) {
87
+			if ( ! is_callable( $output[ 'sanitize_callback' ] ) ) {
88 88
 				return $value;
89 89
 			}
90
-			return call_user_func( $output['sanitize_callback'], $this->value );
90
+			return call_user_func( $output[ 'sanitize_callback' ], $this->value );
91 91
 		}
92 92
 		return $value;
93 93
 	}
@@ -100,22 +100,22 @@  discard block
 block discarded – undo
100 100
 	 * @return string|array
101 101
 	 */
102 102
 	protected function apply_value_pattern( $output, $value ) {
103
-		if ( isset( $output['value_pattern'] ) && ! empty( $output['value_pattern'] ) && is_string( $output['value_pattern'] ) ) {
103
+		if ( isset( $output[ 'value_pattern' ] ) && ! empty( $output[ 'value_pattern' ] ) && is_string( $output[ 'value_pattern' ] ) ) {
104 104
 			if ( ! is_array( $value ) ) {
105
-				$value = str_replace( '$', $value, $output['value_pattern'] );
105
+				$value = str_replace( '$', $value, $output[ 'value_pattern' ] );
106 106
 			}
107 107
 			if ( is_array( $value ) ) {
108 108
 				foreach ( array_keys( $value ) as $value_k ) {
109 109
 					if ( ! is_string( $value[ $value_k ] ) ) {
110 110
 						continue;
111 111
 					}
112
-					if ( isset( $output['choice'] ) ) {
113
-						if ( $output['choice'] === $value_k ) {
114
-							$value[ $output['choice'] ] = str_replace( '$', $value[ $output['choice'] ], $output['value_pattern'] );
112
+					if ( isset( $output[ 'choice' ] ) ) {
113
+						if ( $output[ 'choice' ] === $value_k ) {
114
+							$value[ $output[ 'choice' ] ] = str_replace( '$', $value[ $output[ 'choice' ] ], $output[ 'value_pattern' ] );
115 115
 						}
116 116
 						continue;
117 117
 					}
118
-					$value[ $value_k ] = str_replace( '$', $value[ $value_k ], $output['value_pattern'] );
118
+					$value[ $value_k ] = str_replace( '$', $value[ $value_k ], $output[ 'value_pattern' ] );
119 119
 				}
120 120
 			}
121 121
 			$value = $this->apply_pattern_replace( $output, $value );
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
 	 * @return string|array
132 132
 	 */
133 133
 	protected function apply_pattern_replace( $output, $value ) {
134
-		if ( isset( $output['pattern_replace'] ) && is_array( $output['pattern_replace'] ) ) {
134
+		if ( isset( $output[ 'pattern_replace' ] ) && is_array( $output[ 'pattern_replace' ] ) ) {
135 135
 			$option_type = ( '' !== Kirki::get_config_param( $this->config_id, 'option_type' ) ) ? Kirki::get_config_param( $this->config_id, 'option_type' ) : 'theme_mod';
136 136
 			$option_name = Kirki::get_config_param( $this->config_id, 'option_name' );
137 137
 			$options     = array();
138 138
 			if ( $option_name ) {
139 139
 				$options = ( 'site_option' === $option_type ) ? get_site_option( $option_name ) : get_option( $option_name );
140 140
 			}
141
-			foreach ( $output['pattern_replace'] as $search => $replace ) {
141
+			foreach ( $output[ 'pattern_replace' ] as $search => $replace ) {
142 142
 				$replacement = '';
143 143
 				switch ( $option_type ) {
144 144
 					case 'option':
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 			}
199 199
 
200 200
 			// No need to proceed this if the current value is the same as in the "exclude" value.
201
-			if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) {
202
-				foreach ( $output['exclude'] as $exclude ) {
201
+			if ( isset( $output[ 'exclude' ] ) && is_array( $output[ 'exclude' ] ) ) {
202
+				foreach ( $output[ 'exclude' ] as $exclude ) {
203 203
 					if ( is_array( $value ) ) {
204 204
 						if ( is_array( $exclude ) ) {
205 205
 							$diff1 = array_diff( $value, $exclude );
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 						}
212 212
 						// If 'choice' is defined check for sub-values too.
213 213
 						// Fixes https://github.com/aristath/kirki/issues/1416.
214
-						if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
214
+						if ( isset( $output[ 'choice' ] ) && isset( $value[ $output[ 'choice' ] ] ) && $exclude == $value[ $output[ 'choice' ] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
215 215
 							$skip = true;
216 216
 						}
217 217
 					}
@@ -232,25 +232,25 @@  discard block
 block discarded – undo
232 232
 			// Apply any value patterns defined.
233 233
 			$value = $this->apply_value_pattern( $output, $value );
234 234
 
235
-			if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
236
-				$output['element'] = array_unique( $output['element'] );
237
-				sort( $output['element'] );
238
-				$output['element'] = implode( ',', $output['element'] );
235
+			if ( isset( $output[ 'element' ] ) && is_array( $output[ 'element' ] ) ) {
236
+				$output[ 'element' ] = array_unique( $output[ 'element' ] );
237
+				sort( $output[ 'element' ] );
238
+				$output[ 'element' ] = implode( ',', $output[ 'element' ] );
239 239
 			}
240 240
 
241 241
 			$value = $this->process_value( $value, $output );
242 242
 
243 243
 			// Set the context.
244
-			if ( ! isset( $output['context'] ) || empty( $output['context'] ) ) {
245
-				$output['context'] = array( 'front' );
244
+			if ( ! isset( $output[ 'context' ] ) || empty( $output[ 'context' ] ) ) {
245
+				$output[ 'context' ] = array( 'front' );
246 246
 			}
247 247
 
248 248
 			// Check if this is an admin style.
249 249
 			if ( is_admin() && ! is_customize_preview() ) {
250
-				if ( ! in_array( 'editor', $output['context'] ) ) {
250
+				if ( ! in_array( 'editor', $output[ 'context' ] ) ) {
251 251
 					return;
252 252
 				}
253
-			} elseif ( ! in_array( 'front', $output['context'] ) ) {
253
+			} elseif ( ! in_array( 'front', $output[ 'context' ] ) ) {
254 254
 				return;
255 255
 			}
256 256
 			$this->process_output( $output, $value );
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @return null
268 268
 	 */
269 269
 	protected function process_output( $output, $value ) {
270
-		if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) {
270
+		if ( ! isset( $output[ 'element' ] ) || ! isset( $output[ 'property' ] ) ) {
271 271
 			return;
272 272
 		}
273
-		$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
274
-		$output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
275
-		$output['units']       = ( isset( $output['units'] ) ) ? $output['units'] : '';
276
-		$output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
273
+		$output[ 'media_query' ] = ( isset( $output[ 'media_query' ] ) ) ? $output[ 'media_query' ] : 'global';
274
+		$output[ 'prefix' ]      = ( isset( $output[ 'prefix' ] ) ) ? $output[ 'prefix' ] : '';
275
+		$output[ 'units' ]       = ( isset( $output[ 'units' ] ) ) ? $output[ 'units' ] : '';
276
+		$output[ 'suffix' ]      = ( isset( $output[ 'suffix' ] ) ) ? $output[ 'suffix' ] : '';
277 277
 
278 278
 		// Properties that can accept multiple values.
279 279
 		// Useful for example for gradients where all browsers use the "background-image" property
@@ -282,15 +282,15 @@  discard block
 block discarded – undo
282 282
 			'background-image',
283 283
 			'background',
284 284
 		);
285
-		if ( in_array( $output['property'], $accepts_multiple, true ) ) {
286
-			if ( isset( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) && ! is_array( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) ) {
287
-				$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = (array) $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ];
285
+		if ( in_array( $output[ 'property' ], $accepts_multiple, true ) ) {
286
+			if ( isset( $this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ] ) && ! is_array( $this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ] ) ) {
287
+				$this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ] = (array) $this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ];
288 288
 			}
289
-			$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ][] = $output['prefix'] . $value . $output['units'] . $output['suffix'];
289
+			$this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ][ ] = $output[ 'prefix' ] . $value . $output[ 'units' ] . $output[ 'suffix' ];
290 290
 			return;
291 291
 		}
292 292
 		if ( is_string( $value ) || is_numeric( $value ) ) {
293
-			$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix'];
293
+			$this->styles[ $output[ 'media_query' ] ][ $output[ 'element' ] ][ $output[ 'property' ] ] = $output[ 'prefix' ] . $this->process_property_value( $output[ 'property' ], $value ) . $output[ 'units' ] . $output[ 'suffix' ];
294 294
 		}
295 295
 	}
296 296
 
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 	 * @return string|array
330 330
 	 */
331 331
 	protected function process_value( $value, $output ) {
332
-		if ( isset( $output['property'] ) ) {
333
-			return $this->process_property_value( $output['property'], $value );
332
+		if ( isset( $output[ 'property' ] ) ) {
333
+			return $this->process_property_value( $output[ 'property' ], $value );
334 334
 		}
335 335
 		return $value;
336 336
 	}
Please login to merge, or discard this patch.