Passed
Push — master ( 8a51f3...19e7fa )
by Brian
05:03
created

sd_get_template_part_by_slug()   A

Complexity

Conditions 6

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
nop 1
dl 0
loc 20
rs 9.2222
c 1
b 0
f 0
1
<?php
2
/**
3
 * A file for common functions.
4
 */
5
6
/**
7
 * Return an array of global $pagenow page names that should be used to exclude register_widgets.
8
 *
9
 * Used to block the loading of widgets on certain wp-admin pages to save on memory.
10
 *
11
 * @return mixed|void
12
 */
13
function sd_pagenow_exclude() {
14
	return apply_filters(
15
		'sd_pagenow_exclude',
16
		array(
17
			'upload.php',
18
			'edit-comments.php',
19
			'edit-tags.php',
20
			'index.php',
21
			'media-new.php',
22
			'options-discussion.php',
23
			'options-writing.php',
24
			'edit.php',
25
			'themes.php',
26
			'users.php',
27
		)
28
	);
29
}
30
31
32
/**
33
 * Return an array of widget class names that should be excluded.
34
 *
35
 * Used to conditionally load widgets code.
36
 *
37
 * @return mixed|void
38
 */
39
function sd_widget_exclude() {
40
	return apply_filters( 'sd_widget_exclude', array() );
41
}
42
43
44
/**
45
 * A helper function for margin inputs.
46
 *
47
 * @param string $type
48
 * @param array $overwrite
49
 *
50
 * @return array
51
 */
52
function sd_get_margin_input( $type = 'mt', $overwrite = array(), $include_negatives = true ) {
53
	global $aui_bs5;
54
	$options = array(
55
		''     => __( 'None', 'super-duper' ),
56
		'auto' => __( 'auto', 'super-duper' ),
57
		'0'    => '0',
58
		'1'    => '1',
59
		'2'    => '2',
60
		'3'    => '3',
61
		'4'    => '4',
62
		'5'    => '5',
63
		'6'    => '6',
64
		'7'    => '7',
65
		'8'    => '8',
66
		'9'    => '9',
67
		'10'   => '10',
68
		'11'   => '11',
69
		'12'   => '12',
70
	);
71
72
	if ( $include_negatives ) {
73
		$options['n1']  = '-1';
74
		$options['n2']  = '-2';
75
		$options['n3']  = '-3';
76
		$options['n4']  = '-4';
77
		$options['n5']  = '-5';
78
		$options['n6']  = '-6';
79
		$options['n7']  = '-7';
80
		$options['n8']  = '-8';
81
		$options['n9']  = '-9';
82
		$options['n10'] = '-10';
83
		$options['n11'] = '-11';
84
		$options['n12'] = '-12';
85
	}
86
87
	$defaults = array(
88
		'type'     => 'select',
89
		'title'    => __( 'Margin top', 'super-duper' ),
90
		'options'  => $options,
91
		'default'  => '',
92
		'desc_tip' => true,
93
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
94
	);
95
96
	// title
97
	if ( $type == 'mt' ) {
98
		$defaults['title'] = __( 'Margin top', 'super-duper' );
99
		$defaults['icon']  = 'box-top';
100
		$defaults['row']   = array(
101
			'title' => __( 'Margins', 'super-duper' ),
102
			'key'   => 'wrapper-margins',
103
			'open'  => true,
104
			'class' => 'text-center',
105
		);
106
	} elseif ( $type == 'mr' ) {
107
		$defaults['title'] = __( 'Margin right', 'super-duper' );
108
		$defaults['icon']  = 'box-right';
109
		$defaults['row']   = array(
110
			'key' => 'wrapper-margins',
111
		);
112
	} elseif ( $type == 'mb' ) {
113
		$defaults['title'] = __( 'Margin bottom', 'super-duper' );
114
		$defaults['icon']  = 'box-bottom';
115
		$defaults['row']   = array(
116
			'key' => 'wrapper-margins',
117
		);
118
	} elseif ( $type == 'ml' ) {
119
		$defaults['title'] = __( 'Margin left', 'super-duper' );
120
		$defaults['icon']  = 'box-left';
121
		$defaults['row']   = array(
122
			'key'   => 'wrapper-margins',
123
			'close' => true,
124
		);
125
	}
126
127
	$input = wp_parse_args( $overwrite, $defaults );
128
129
	return $input;
130
}
131
132
/**
133
 * A helper function for padding inputs.
134
 *
135
 * @param string $type
136
 * @param array $overwrite
137
 *
138
 * @return array
139
 */
140
function sd_get_padding_input( $type = 'pt', $overwrite = array() ) {
141
	$options = array(
142
		''   => __( 'None', 'super-duper' ),
143
		'0'  => '0',
144
		'1'  => '1',
145
		'2'  => '2',
146
		'3'  => '3',
147
		'4'  => '4',
148
		'5'  => '5',
149
		'6'  => '6',
150
		'7'  => '7',
151
		'8'  => '8',
152
		'9'  => '9',
153
		'10' => '10',
154
		'11' => '11',
155
		'12' => '12',
156
	);
157
158
	$defaults = array(
159
		'type'     => 'select',
160
		'title'    => __( 'Padding top', 'super-duper' ),
161
		'options'  => $options,
162
		'default'  => '',
163
		'desc_tip' => true,
164
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
165
	);
166
167
	// title
168
	if ( $type == 'pt' ) {
169
		$defaults['title'] = __( 'Padding top', 'super-duper' );
170
		$defaults['icon']  = 'box-top';
171
		$defaults['row']   = array(
172
			'title' => __( 'Padding', 'super-duper' ),
173
			'key'   => 'wrapper-padding',
174
			'open'  => true,
175
			'class' => 'text-center',
176
		);
177
	} elseif ( $type == 'pr' ) {
178
		$defaults['title'] = __( 'Padding right', 'super-duper' );
179
		$defaults['icon']  = 'box-right';
180
		$defaults['row']   = array(
181
			'key' => 'wrapper-padding',
182
		);
183
	} elseif ( $type == 'pb' ) {
184
		$defaults['title'] = __( 'Padding bottom', 'super-duper' );
185
		$defaults['icon']  = 'box-bottom';
186
		$defaults['row']   = array(
187
			'key' => 'wrapper-padding',
188
		);
189
	} elseif ( $type == 'pl' ) {
190
		$defaults['title'] = __( 'Padding left', 'super-duper' );
191
		$defaults['icon']  = 'box-left';
192
		$defaults['row']   = array(
193
			'key'   => 'wrapper-padding',
194
			'close' => true,
195
196
		);
197
	}
198
199
	$input = wp_parse_args( $overwrite, $defaults );
200
201
	return $input;
202
}
203
204
/**
205
 * A helper function for border inputs.
206
 *
207
 * @param string $type
208
 * @param array $overwrite
209
 *
210
 * @return array
211
 */
212
function sd_get_border_input( $type = 'border', $overwrite = array() ) {
213
	global $aui_bs5;
214
215
	$defaults = array(
216
		'type'     => 'select',
217
		'title'    => __( 'Border', 'super-duper' ),
218
		'options'  => array(),
219
		'default'  => '',
220
		'desc_tip' => true,
221
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
222
	);
223
224
	// title
225
	if ( 'rounded' === $type ) {
226
		$defaults['title']           = __( 'Border radius type', 'super-duper' );
227
		$defaults['options']         = array(
228
			''               => __( 'Default', 'super-duper' ),
229
			'rounded'        => 'rounded',
230
			'rounded-top'    => 'rounded-top',
231
			'rounded-right'  => 'rounded-right',
232
			'rounded-bottom' => 'rounded-bottom',
233
			'rounded-left'   => 'rounded-left',
234
		);
235
		$defaults['element_require'] = '[%border%]';
236
	} elseif ( 'rounded_size' === $type ) {
237
		$defaults['title'] = __( 'Border radius size', 'super-duper' );
238
239
		if ( $aui_bs5 ) {
240
			$defaults['options'] = array(
241
				''       => __( 'Default', 'super-duper' ),
242
				'0'      => '0',
243
				'1'      => '1',
244
				'2'      => '2',
245
				'3'      => '3',
246
				'4'      => '4',
247
				'circle' => 'circle',
248
				'pill'   => 'pill',
249
			);
250
		} else {
251
			$defaults['options'] = array(
252
				''   => __( 'Default', 'super-duper' ),
253
				'sm' => __( 'Small', 'super-duper' ),
254
				'lg' => __( 'Large', 'super-duper' ),
255
			);
256
		}
257
		$defaults['element_require'] = '[%border%]';
258
	} elseif ( 'width' === $type ) { // BS%
259
		$defaults['title']           = __( 'Border width', 'super-duper' );
260
		$defaults['options']         = array(
261
			''         => __( 'Default', 'super-duper' ),
262
			'border-2' => '2',
263
			'border-3' => '3',
264
			'border-4' => '4',
265
			'border-5' => '5',
266
		);
267
		$defaults['element_require'] = $aui_bs5 ? '[%border%]' : '1==2';
268
	} elseif ( 'opacity' === $type ) { // BS%
269
		$defaults['title']           = __( 'Border opacity', 'super-duper' );
270
		$defaults['options']         = array(
271
			''                  => __( 'Default', 'super-duper' ),
272
			'border-opacity-75' => '75%',
273
			'border-opacity-50' => '50%',
274
			'border-opacity-25' => '25%',
275
			'border-opacity-10' => '10%',
276
		);
277
		$defaults['element_require'] = $aui_bs5 ? '[%border%]' : '1==2';
278
	} elseif ( 'type' === $type ) {
279
		$defaults['title']           = __( 'Border show', 'super-duper' );
280
		$defaults['options']         = array(
281
			'border'          => __( 'Full (set color to show)', 'super-duper' ),
282
			'border-top'      => __( 'Top', 'super-duper' ),
283
			'border-bottom'   => __( 'Bottom', 'super-duper' ),
284
			'border-left'     => __( 'Left', 'super-duper' ),
285
			'border-right'    => __( 'Right', 'super-duper' ),
286
			'border-top-0'    => __( '-Top', 'super-duper' ),
287
			'border-bottom-0' => __( '-Bottom', 'super-duper' ),
288
			'border-left-0'   => __( '-Left', 'super-duper' ),
289
			'border-right-0'  => __( '-Right', 'super-duper' ),
290
		);
291
		$defaults['element_require'] = '[%border%]';
292
293
	} else {
294
		$defaults['title']   = __( 'Border color', 'super-duper' );
295
		$defaults['options'] = array(
296
			                       ''  => __( 'Default', 'super-duper' ),
297
			                       '0' => __( 'None', 'super-duper' ),
298
		                       ) + sd_aui_colors();
299
	}
300
301
	$input = wp_parse_args( $overwrite, $defaults );
302
303
	return $input;
304
}
305
306
/**
307
 * A helper function for shadow inputs.
308
 *
309
 * @param string $type
310
 * @param array $overwrite
311
 *
312
 * @return array
313
 */
314
function sd_get_shadow_input( $type = 'shadow', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

314
function sd_get_shadow_input( /** @scrutinizer ignore-unused */ $type = 'shadow', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
315
	$options = array(
316
		''          => __( 'None', 'super-duper' ),
317
		'shadow-sm' => __( 'Small', 'super-duper' ),
318
		'shadow'    => __( 'Regular', 'super-duper' ),
319
		'shadow-lg' => __( 'Large', 'super-duper' ),
320
	);
321
322
	$defaults = array(
323
		'type'     => 'select',
324
		'title'    => __( 'Shadow', 'super-duper' ),
325
		'options'  => $options,
326
		'default'  => '',
327
		'desc_tip' => true,
328
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
329
	);
330
331
	$input = wp_parse_args( $overwrite, $defaults );
332
333
	return $input;
334
}
335
336
/**
337
 * A helper function for background inputs.
338
 *
339
 * @param string $type
340
 * @param array $overwrite
341
 *
342
 * @return array
343
 */
344
function sd_get_background_input( $type = 'bg', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

344
function sd_get_background_input( /** @scrutinizer ignore-unused */ $type = 'bg', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
345
	$options = array(
346
		           ''            => __( 'None', 'super-duper' ),
347
		           'transparent' => __( 'Transparent', 'super-duper' ),
348
	           ) + sd_aui_colors();
349
350
	$defaults = array(
351
		'type'     => 'select',
352
		'title'    => __( 'Background color', 'super-duper' ),
353
		'options'  => $options,
354
		'default'  => '',
355
		'desc_tip' => true,
356
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
357
	);
358
359
	$input = wp_parse_args( $overwrite, $defaults );
360
361
	return $input;
362
}
363
364
/**
365
 * A function to get th opacity options.
366
 *
367
 * @param $type
368
 * @param $overwrite
369
 *
370
 * @return array
371
 */
372
function sd_get_opacity_input( $type = 'opacity', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

372
function sd_get_opacity_input( /** @scrutinizer ignore-unused */ $type = 'opacity', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
373
	$options = array(
374
		''            => __( 'Default', 'super-duper' ),
375
		'opacity-10'  => '10%',
376
		'opacity-15'  => '15%',
377
		'opacity-25'  => '25%',
378
		'opacity-35'  => '35%',
379
		'opacity-40'  => '40%',
380
		'opacity-50'  => '50%',
381
		'opacity-60'  => '60%',
382
		'opacity-65'  => '65%',
383
		'opacity-70'  => '70%',
384
		'opacity-75'  => '75%',
385
		'opacity-80'  => '80%',
386
		'opacity-90'  => '90%',
387
		'opacity-100' => '100%',
388
	);
389
390
	$defaults = array(
391
		'type'     => 'select',
392
		'title'    => __( 'Opacity', 'super-duper' ),
393
		'options'  => $options,
394
		'default'  => '',
395
		'desc_tip' => true,
396
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
397
	);
398
399
	$input = wp_parse_args( $overwrite, $defaults );
400
401
	return $input;
402
}
403
404
/**
405
 * A helper function for a set of background inputs.
406
 *
407
 * @param string $type
408
 * @param array $overwrite
409
 *
410
 * @return array
411
 */
412
function sd_get_background_inputs( $type = 'bg', $overwrite = array(), $overwrite_color = array(), $overwrite_gradient = array(), $overwrite_image = array(), $include_button_colors = false ) {
413
414
	$color_options = $include_button_colors ? sd_aui_colors( false, true, true, true ) : sd_aui_colors();
415
416
	$options = array(
417
		           ''            => __( 'None', 'super-duper' ),
418
		           'transparent' => __( 'Transparent', 'super-duper' ),
419
	           ) + $color_options;
420
421
	if ( false !== $overwrite_color ) {
422
		$options['custom-color'] = __( 'Custom Color', 'super-duper' );
423
	}
424
425
	if ( false !== $overwrite_gradient ) {
426
		$options['custom-gradient'] = __( 'Custom Gradient', 'super-duper' );
427
	}
428
429
	$defaults = array(
430
		'type'     => 'select',
431
		'title'    => __( 'Background Color', 'super-duper' ),
432
		'options'  => $options,
433
		'default'  => '',
434
		'desc_tip' => true,
435
		'group'    => __( 'Background', 'super-duper' ),
436
	);
437
438
	if ( $overwrite !== false ) {
0 ignored issues
show
introduced by
The condition $overwrite !== false is always true.
Loading history...
439
		$input[ $type ] = wp_parse_args( $overwrite, $defaults );
0 ignored issues
show
Comprehensibility Best Practice introduced by
$input was never initialized. Although not strictly required by PHP, it is generally a good practice to add $input = array(); before regardless.
Loading history...
440
	}
441
442
	if ( $overwrite_color !== false ) {
443
		$input[ $type . '_color' ] = wp_parse_args(
444
			$overwrite_color,
445
			array(
446
				'type'            => 'color',
447
				'title'           => __( 'Custom color', 'super-duper' ),
448
				'placeholder'     => '',
449
				'default'         => '#0073aa',
450
				'desc_tip'        => true,
451
				'group'           => __( 'Background', 'super-duper' ),
452
				'element_require' => '[%' . $type . '%]=="custom-color"',
453
			)
454
		);
455
	}
456
457
	if ( $overwrite_gradient !== false ) {
458
		$input[ $type . '_gradient' ] = wp_parse_args(
459
			$overwrite_gradient,
460
			array(
461
				'type'            => 'gradient',
462
				'title'           => __( 'Custom gradient', 'super-duper' ),
463
				'placeholder'     => '',
464
				'default'         => 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
465
				'desc_tip'        => true,
466
				'group'           => __( 'Background', 'super-duper' ),
467
				'element_require' => '[%' . $type . '%]=="custom-gradient"',
468
			)
469
		);
470
	}
471
472
	if ( $overwrite_image !== false ) {
473
474
		$input[ $type . '_image_fixed' ] = array(
475
			'type'            => 'checkbox',
476
			'title'           => __( 'Fixed background', 'super-duper' ),
477
			'default'         => '',
478
			'desc_tip'        => true,
479
			'group'           => ! empty( $overwrite_image['group'] ) ? $overwrite_image['group'] : __( 'Background', 'super-duper' ),
480
			'element_require' => '( [%' . $type . '%]=="" || [%' . $type . '%]=="custom-color" || [%' . $type . '%]=="custom-gradient" || [%' . $type . '%]=="transparent" )',
481
482
		);
483
484
		$input[ $type . '_image_use_featured' ] = array(
485
			'type'            => 'checkbox',
486
			'title'           => __( 'Use featured image', 'super-duper' ),
487
			'default'         => '',
488
			'desc_tip'        => true,
489
			'group'           => ! empty( $overwrite_image['group'] ) ? $overwrite_image['group'] : __( 'Background', 'super-duper' ),
490
			'element_require' => '( [%' . $type . '%]=="" || [%' . $type . '%]=="custom-color" || [%' . $type . '%]=="custom-gradient" || [%' . $type . '%]=="transparent" )',
491
492
		);
493
494
		$input[ $type . '_image' ] = wp_parse_args(
495
			$overwrite_image,
496
			array(
497
				'type'        => 'image',
498
				'title'       => __( 'Custom image', 'super-duper' ),
499
				'placeholder' => '',
500
				'default'     => '',
501
				'desc_tip'    => true,
502
				'group'       => __( 'Background', 'super-duper' ),
503
				//          'element_require' => ' ![%' . $type . '_image_use_featured%] '
504
			)
505
		);
506
507
		$input[ $type . '_image_id' ] = wp_parse_args(
508
			$overwrite_image,
509
			array(
510
				'type'        => 'hidden',
511
				'hidden_type' => 'number',
512
				'title'       => '',
513
				'placeholder' => '',
514
				'default'     => '',
515
				'group'       => __( 'Background', 'super-duper' ),
516
			)
517
		);
518
519
		$input[ $type . '_image_xy' ] = wp_parse_args(
520
			$overwrite_image,
521
			array(
522
				'type'        => 'image_xy',
523
				'title'       => '',
524
				'placeholder' => '',
525
				'default'     => '',
526
				'group'       => __( 'Background', 'super-duper' ),
527
			)
528
		);
529
	}
530
531
	return $input;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $input does not seem to be defined for all execution paths leading up to this point.
Loading history...
532
}
533
534
/**
535
 * A helper function for a set of inputs for the shape divider.
536
 *
537
 * @param string $type
538
 * @param array $overwrite
539
 *
540
 * @return array
541
 */
542
function sd_get_shape_divider_inputs( $type = 'sd', $overwrite = array(), $overwrite_color = array(), $overwrite_gradient = array(), $overwrite_image = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $overwrite_image is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

542
function sd_get_shape_divider_inputs( $type = 'sd', $overwrite = array(), $overwrite_color = array(), $overwrite_gradient = array(), /** @scrutinizer ignore-unused */ $overwrite_image = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
543
544
	$options = array(
545
		''                      => __( 'None', 'super-duper' ),
546
		'mountains'             => __( 'Mountains', 'super-duper' ),
547
		'drops'                 => __( 'Drops', 'super-duper' ),
548
		'clouds'                => __( 'Clouds', 'super-duper' ),
549
		'zigzag'                => __( 'Zigzag', 'super-duper' ),
550
		'pyramids'              => __( 'Pyramids', 'super-duper' ),
551
		'triangle'              => __( 'Triangle', 'super-duper' ),
552
		'triangle-asymmetrical' => __( 'Triangle Asymmetrical', 'super-duper' ),
553
		'tilt'                  => __( 'Tilt', 'super-duper' ),
554
		'opacity-tilt'          => __( 'Opacity Tilt', 'super-duper' ),
555
		'opacity-fan'           => __( 'Opacity Fan', 'super-duper' ),
556
		'curve'                 => __( 'Curve', 'super-duper' ),
557
		'curve-asymmetrical'    => __( 'Curve Asymmetrical', 'super-duper' ),
558
		'waves'                 => __( 'Waves', 'super-duper' ),
559
		'wave-brush'            => __( 'Wave Brush', 'super-duper' ),
560
		'waves-pattern'         => __( 'Waves Pattern', 'super-duper' ),
561
		'arrow'                 => __( 'Arrow', 'super-duper' ),
562
		'split'                 => __( 'Split', 'super-duper' ),
563
		'book'                  => __( 'Book', 'super-duper' ),
564
	);
565
566
	$defaults = array(
567
		'type'     => 'select',
568
		'title'    => __( 'Type', 'super-duper' ),
569
		'options'  => $options,
570
		'default'  => '',
571
		'desc_tip' => true,
572
		'group'    => __( 'Shape Divider', 'super-duper' ),
573
	);
574
575
	$input[ $type ] = wp_parse_args( $overwrite, $defaults );
0 ignored issues
show
Comprehensibility Best Practice introduced by
$input was never initialized. Although not strictly required by PHP, it is generally a good practice to add $input = array(); before regardless.
Loading history...
576
577
	$input[ $type . '_notice' ] = array(
578
		'type'            => 'notice',
579
		'desc'            => __( 'Parent element must be position `relative`', 'super-duper' ),
580
		'status'          => 'warning',
581
		'group'           => __( 'Shape Divider', 'super-duper' ),
582
		'element_require' => '[%' . $type . '%]!=""',
583
	);
584
585
	$input[ $type . '_position' ] = wp_parse_args(
586
		$overwrite_color,
587
		array(
588
			'type'            => 'select',
589
			'title'           => __( 'Position', 'super-duper' ),
590
			'options'         => array(
591
				'top'    => __( 'Top', 'super-duper' ),
592
				'bottom' => __( 'Bottom', 'super-duper' ),
593
			),
594
			'desc_tip'        => true,
595
			'group'           => __( 'Shape Divider', 'super-duper' ),
596
			'element_require' => '[%' . $type . '%]!=""',
597
		)
598
	);
599
600
	$options = array(
601
		           ''            => __( 'None', 'super-duper' ),
602
		           'transparent' => __( 'Transparent', 'super-duper' ),
603
	           ) + sd_aui_colors()
604
	           + array(
605
		           'custom-color' => __( 'Custom Color', 'super-duper' ),
606
	           );
607
608
	$input[ $type . '_color' ] = wp_parse_args(
609
		$overwrite_color,
610
		array(
611
			'type'            => 'select',
612
			'title'           => __( 'Color', 'super-duper' ),
613
			'options'         => $options,
614
			'desc_tip'        => true,
615
			'group'           => __( 'Shape Divider', 'super-duper' ),
616
			'element_require' => '[%' . $type . '%]!=""',
617
		)
618
	);
619
620
	$input[ $type . '_custom_color' ] = wp_parse_args(
621
		$overwrite_color,
622
		array(
623
			'type'            => 'color',
624
			'title'           => __( 'Custom color', 'super-duper' ),
625
			'placeholder'     => '',
626
			'default'         => '#0073aa',
627
			'desc_tip'        => true,
628
			'group'           => __( 'Shape Divider', 'super-duper' ),
629
			'element_require' => '[%' . $type . '_color%]=="custom-color" && [%' . $type . '%]!=""',
630
		)
631
	);
632
633
	$input[ $type . '_width' ] = wp_parse_args(
634
		$overwrite_gradient,
635
		array(
636
			'type'              => 'range',
637
			'title'             => __( 'Width', 'super-duper' ),
638
			'placeholder'       => '',
639
			'default'           => '200',
640
			'desc_tip'          => true,
641
			'custom_attributes' => array(
642
				'min' => 100,
643
				'max' => 300,
644
			),
645
			'group'             => __( 'Shape Divider', 'super-duper' ),
646
			'element_require'   => '[%' . $type . '%]!=""',
647
		)
648
	);
649
650
	$input[ $type . '_height' ] = array(
651
		'type'              => 'range',
652
		'title'             => __( 'Height', 'super-duper' ),
653
		'default'           => '100',
654
		'desc_tip'          => true,
655
		'custom_attributes' => array(
656
			'min' => 0,
657
			'max' => 500,
658
		),
659
		'group'             => __( 'Shape Divider', 'super-duper' ),
660
		'element_require'   => '[%' . $type . '%]!=""',
661
	);
662
663
	$requires = array(
664
		'mountains'             => array( 'flip' ),
665
		'drops'                 => array( 'flip', 'invert' ),
666
		'clouds'                => array( 'flip', 'invert' ),
667
		'zigzag'                => array(),
668
		'pyramids'              => array( 'flip', 'invert' ),
669
		'triangle'              => array( 'invert' ),
670
		'triangle-asymmetrical' => array( 'flip', 'invert' ),
671
		'tilt'                  => array( 'flip' ),
672
		'opacity-tilt'          => array( 'flip' ),
673
		'opacity-fan'           => array(),
674
		'curve'                 => array( 'invert' ),
675
		'curve-asymmetrical'    => array( 'flip', 'invert' ),
676
		'waves'                 => array( 'flip', 'invert' ),
677
		'wave-brush'            => array( 'flip' ),
678
		'waves-pattern'         => array( 'flip' ),
679
		'arrow'                 => array( 'invert' ),
680
		'split'                 => array( 'invert' ),
681
		'book'                  => array( 'invert' ),
682
	);
683
684
	$input[ $type . '_flip' ] = array(
685
		'type'            => 'checkbox',
686
		'title'           => __( 'Flip', 'super-duper' ),
687
		'default'         => '',
688
		'desc_tip'        => true,
689
		'group'           => __( 'Shape Divider', 'super-duper' ),
690
		'element_require' => sd_get_element_require_string( $requires, 'flip', 'sd' ),
691
	);
692
693
	$input[ $type . '_invert' ] = array(
694
		'type'            => 'checkbox',
695
		'title'           => __( 'Invert', 'super-duper' ),
696
		'default'         => '',
697
		'desc_tip'        => true,
698
		'group'           => __( 'Shape Divider', 'super-duper' ),
699
		'element_require' => sd_get_element_require_string( $requires, 'invert', 'sd' ),
700
	);
701
702
	$input[ $type . '_btf' ] = array(
703
		'type'            => 'checkbox',
704
		'title'           => __( 'Bring to front', 'super-duper' ),
705
		'default'         => '',
706
		'desc_tip'        => true,
707
		'group'           => __( 'Shape Divider', 'super-duper' ),
708
		'element_require' => '[%' . $type . '%]!=""',
709
710
	);
711
712
	return $input;
713
}
714
715
/**
716
 * Get the element require sting.
717
 *
718
 * @param $args
719
 * @param $key
720
 * @param $type
721
 *
722
 * @return string
723
 */
724
function sd_get_element_require_string( $args, $key, $type ) {
725
	$output   = '';
726
	$requires = array();
727
728
	if ( ! empty( $args ) ) {
729
		foreach ( $args as $t => $k ) {
730
			if ( in_array( $key, $k ) ) {
731
				$requires[] = '[%' . $type . '%]=="' . $t . '"';
732
			}
733
		}
734
735
		if ( ! empty( $requires ) ) {
736
			$output = '(' . implode( ' || ', $requires ) . ')';
737
		}
738
	}
739
740
	return $output;
741
}
742
743
/**
744
 * A helper function for text color inputs.
745
 *
746
 * @param string $type
747
 * @param array $overwrite
748
 *
749
 * @return array
750
 */
751
function sd_get_text_color_input( $type = 'text_color', $overwrite = array(), $has_custom = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

751
function sd_get_text_color_input( /** @scrutinizer ignore-unused */ $type = 'text_color', $overwrite = array(), $has_custom = false ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
752
	$options = array(
753
		           '' => __( 'None', 'super-duper' ),
754
	           ) + sd_aui_colors();
755
756
	if ( $has_custom ) {
757
		$options['custom'] = __( 'Custom color', 'super-duper' );
758
	}
759
760
	$defaults = array(
761
		'type'     => 'select',
762
		'title'    => __( 'Text color', 'super-duper' ),
763
		'options'  => $options,
764
		'default'  => '',
765
		'desc_tip' => true,
766
		'group'    => __( 'Typography', 'super-duper' ),
767
	);
768
769
	$input = wp_parse_args( $overwrite, $defaults );
770
771
	return $input;
772
}
773
774
function sd_get_text_color_input_group( $type = 'text_color', $overwrite = array(), $overwrite_custom = array() ) {
775
	$inputs = array();
776
777
	if ( $overwrite !== false ) {
778
		$inputs[ $type ] = sd_get_text_color_input( $type, $overwrite, true );
779
	}
780
781
	if ( $overwrite_custom !== false ) {
782
		$custom            = $type . '_custom';
783
		$inputs[ $custom ] = sd_get_custom_color_input( $custom, $overwrite_custom, $type );
784
	}
785
786
	return $inputs;
787
}
788
789
/**
790
 * A helper function for custom color.
791
 *
792
 * @param string $type
793
 * @param array $overwrite
794
 *
795
 * @return array
796
 */
797
function sd_get_custom_color_input( $type = 'color_custom', $overwrite = array(), $parent_type = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

797
function sd_get_custom_color_input( /** @scrutinizer ignore-unused */ $type = 'color_custom', $overwrite = array(), $parent_type = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
798
799
	$defaults = array(
800
		'type'        => 'color',
801
		'title'       => __( 'Custom color', 'super-duper' ),
802
		'default'     => '',
803
		'placeholder' => '',
804
		'desc_tip'    => true,
805
		'group'       => __( 'Typography', 'super-duper' ),
806
	);
807
808
	if ( $parent_type ) {
809
		$defaults['element_require'] = '[%' . $parent_type . '%]=="custom"';
810
	}
811
812
	$input = wp_parse_args( $overwrite, $defaults );
813
814
	return $input;
815
}
816
817
/**
818
 * A helper function for column inputs.
819
 *
820
 * @param string $type
821
 * @param array $overwrite
822
 *
823
 * @return array
824
 */
825
function sd_get_col_input( $type = 'col', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

825
function sd_get_col_input( /** @scrutinizer ignore-unused */ $type = 'col', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
826
827
	$device_size = '';
828
	if ( ! empty( $overwrite['device_type'] ) ) {
829
		if ( $overwrite['device_type'] == 'Tablet' ) {
830
			$device_size = '-md';
0 ignored issues
show
Unused Code introduced by
The assignment to $device_size is dead and can be removed.
Loading history...
831
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
832
			$device_size = '-lg';
833
		}
834
	}
835
	$options = array(
836
		''     => __( 'Default', 'super-duper' ),
837
		'auto' => __( 'auto', 'super-duper' ),
838
		'1'    => '1/12',
839
		'2'    => '2/12',
840
		'3'    => '3/12',
841
		'4'    => '4/12',
842
		'5'    => '5/12',
843
		'6'    => '6/12',
844
		'7'    => '7/12',
845
		'8'    => '8/12',
846
		'9'    => '9/12',
847
		'10'   => '10/12',
848
		'11'   => '11/12',
849
		'12'   => '12/12',
850
	);
851
852
	$defaults = array(
853
		'type'            => 'select',
854
		'title'           => __( 'Column width', 'super-duper' ),
855
		'options'         => $options,
856
		'default'         => '',
857
		'desc_tip'        => true,
858
		'group'           => __( 'Container', 'super-duper' ),
859
		'element_require' => '[%container%]=="col"',
860
	);
861
862
	$input = wp_parse_args( $overwrite, $defaults );
863
864
	return $input;
865
}
866
867
/**
868
 * A helper function for row columns inputs.
869
 *
870
 * @param string $type
871
 * @param array $overwrite
872
 *
873
 * @return array
874
 */
875
function sd_get_row_cols_input( $type = 'row_cols', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

875
function sd_get_row_cols_input( /** @scrutinizer ignore-unused */ $type = 'row_cols', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
876
877
	$device_size = '';
878
	if ( ! empty( $overwrite['device_type'] ) ) {
879
		if ( $overwrite['device_type'] == 'Tablet' ) {
880
			$device_size = '-md';
0 ignored issues
show
Unused Code introduced by
The assignment to $device_size is dead and can be removed.
Loading history...
881
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
882
			$device_size = '-lg';
883
		}
884
	}
885
	$options = array(
886
		''  => __( 'auto', 'super-duper' ),
887
		'1' => '1',
888
		'2' => '2',
889
		'3' => '3',
890
		'4' => '4',
891
		'5' => '5',
892
		'6' => '6',
893
	);
894
895
	$defaults = array(
896
		'type'            => 'select',
897
		'title'           => __( 'Row columns', 'super-duper' ),
898
		'options'         => $options,
899
		'default'         => '',
900
		'desc_tip'        => true,
901
		'group'           => __( 'Container', 'super-duper' ),
902
		'element_require' => '[%container%]=="row"',
903
	);
904
905
	$input = wp_parse_args( $overwrite, $defaults );
906
907
	return $input;
908
}
909
910
/**
911
 * A helper function for text align inputs.
912
 *
913
 * @param string $type
914
 * @param array $overwrite
915
 *
916
 * @return array
917
 */
918
function sd_get_text_align_input( $type = 'text_align', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

918
function sd_get_text_align_input( /** @scrutinizer ignore-unused */ $type = 'text_align', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
919
920
	$device_size = '';
921
	if ( ! empty( $overwrite['device_type'] ) ) {
922
		if ( $overwrite['device_type'] == 'Tablet' ) {
923
			$device_size = '-md';
924
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
925
			$device_size = '-lg';
926
		}
927
	}
928
	$options = array(
929
		''                                => __( 'Default', 'super-duper' ),
930
		'text' . $device_size . '-left'   => __( 'Left', 'super-duper' ),
931
		'text' . $device_size . '-right'  => __( 'Right', 'super-duper' ),
932
		'text' . $device_size . '-center' => __( 'Center', 'super-duper' ),
933
	);
934
935
	$defaults = array(
936
		'type'     => 'select',
937
		'title'    => __( 'Text align', 'super-duper' ),
938
		'options'  => $options,
939
		'default'  => '',
940
		'desc_tip' => true,
941
		'group'    => __( 'Typography', 'super-duper' ),
942
	);
943
944
	$input = wp_parse_args( $overwrite, $defaults );
945
946
	return $input;
947
}
948
949
/**
950
 * A helper function for display inputs.
951
 *
952
 * @param string $type
953
 * @param array $overwrite
954
 *
955
 * @return array
956
 */
957
function sd_get_display_input( $type = 'display', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

957
function sd_get_display_input( /** @scrutinizer ignore-unused */ $type = 'display', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
958
959
	$device_size = '';
960
	if ( ! empty( $overwrite['device_type'] ) ) {
961
		if ( $overwrite['device_type'] == 'Tablet' ) {
962
			$device_size = '-md';
963
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
964
			$device_size = '-lg';
965
		}
966
	}
967
	$options = array(
968
		''                                   => __( 'Default', 'super-duper' ),
969
		'd' . $device_size . '-none'         => 'none',
970
		'd' . $device_size . '-inline'       => 'inline',
971
		'd' . $device_size . '-inline-block' => 'inline-block',
972
		'd' . $device_size . '-block'        => 'block',
973
		'd' . $device_size . '-table'        => 'table',
974
		'd' . $device_size . '-table-cell'   => 'table-cell',
975
		'd' . $device_size . '-table-row'    => 'table-row',
976
		'd' . $device_size . '-flex'         => 'flex',
977
		'd' . $device_size . '-inline-flex'  => 'inline-flex',
978
	);
979
980
	$defaults = array(
981
		'type'     => 'select',
982
		'title'    => __( 'Display', 'super-duper' ),
983
		'options'  => $options,
984
		'default'  => '',
985
		'desc_tip' => true,
986
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
987
	);
988
989
	$input = wp_parse_args( $overwrite, $defaults );
990
991
	return $input;
992
}
993
994
/**
995
 * A helper function for text justify inputs.
996
 *
997
 * @param string $type
998
 * @param array $overwrite
999
 *
1000
 * @return array
1001
 */
1002
function sd_get_text_justify_input( $type = 'text_justify', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1002
function sd_get_text_justify_input( /** @scrutinizer ignore-unused */ $type = 'text_justify', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1003
1004
	$defaults = array(
1005
		'type'     => 'checkbox',
1006
		'title'    => __( 'Text justify', 'super-duper' ),
1007
		'default'  => '',
1008
		'desc_tip' => true,
1009
		'group'    => __( 'Typography', 'super-duper' ),
1010
	);
1011
1012
	$input = wp_parse_args( $overwrite, $defaults );
1013
1014
	return $input;
1015
}
1016
1017
/**
1018
 * Get the AUI colors.
1019
 *
1020
 * @param $include_branding
1021
 * @param $include_outlines
1022
 * @param $outline_button_only_text
1023
 *
1024
 * @return array
1025
 */
1026
function sd_aui_colors( $include_branding = false, $include_outlines = false, $outline_button_only_text = false, $include_translucent = false ) {
1027
	$theme_colors = array();
1028
1029
	$theme_colors['primary']   = __( 'Primary', 'super-duper' );
1030
	$theme_colors['secondary'] = __( 'Secondary', 'super-duper' );
1031
	$theme_colors['success']   = __( 'Success', 'super-duper' );
1032
	$theme_colors['danger']    = __( 'Danger', 'super-duper' );
1033
	$theme_colors['warning']   = __( 'Warning', 'super-duper' );
1034
	$theme_colors['info']      = __( 'Info', 'super-duper' );
1035
	$theme_colors['light']     = __( 'Light', 'super-duper' );
1036
	$theme_colors['dark']      = __( 'Dark', 'super-duper' );
1037
	$theme_colors['white']     = __( 'White', 'super-duper' );
1038
	$theme_colors['purple']    = __( 'Purple', 'super-duper' );
1039
	$theme_colors['salmon']    = __( 'Salmon', 'super-duper' );
1040
	$theme_colors['cyan']      = __( 'Cyan', 'super-duper' );
1041
	$theme_colors['gray']      = __( 'Gray', 'super-duper' );
1042
	$theme_colors['muted']     = __( 'Muted', 'super-duper' );
1043
	$theme_colors['gray-dark'] = __( 'Gray dark', 'super-duper' );
1044
	$theme_colors['indigo']    = __( 'Indigo', 'super-duper' );
1045
	$theme_colors['orange']    = __( 'Orange', 'super-duper' );
1046
1047
	if ( $include_outlines ) {
1048
		$button_only                       = $outline_button_only_text ? ' ' . __( '(button only)', 'super-duper' ) : '';
1049
		$theme_colors['outline-primary']   = __( 'Primary outline', 'super-duper' ) . $button_only;
1050
		$theme_colors['outline-secondary'] = __( 'Secondary outline', 'super-duper' ) . $button_only;
1051
		$theme_colors['outline-success']   = __( 'Success outline', 'super-duper' ) . $button_only;
1052
		$theme_colors['outline-danger']    = __( 'Danger outline', 'super-duper' ) . $button_only;
1053
		$theme_colors['outline-warning']   = __( 'Warning outline', 'super-duper' ) . $button_only;
1054
		$theme_colors['outline-info']      = __( 'Info outline', 'super-duper' ) . $button_only;
1055
		$theme_colors['outline-light']     = __( 'Light outline', 'super-duper' ) . $button_only;
1056
		$theme_colors['outline-dark']      = __( 'Dark outline', 'super-duper' ) . $button_only;
1057
		$theme_colors['outline-white']     = __( 'White outline', 'super-duper' ) . $button_only;
1058
		$theme_colors['outline-purple']    = __( 'Purple outline', 'super-duper' ) . $button_only;
1059
		$theme_colors['outline-salmon']    = __( 'Salmon outline', 'super-duper' ) . $button_only;
1060
		$theme_colors['outline-cyan']      = __( 'Cyan outline', 'super-duper' ) . $button_only;
1061
		$theme_colors['outline-gray']      = __( 'Gray outline', 'super-duper' ) . $button_only;
1062
		$theme_colors['outline-gray-dark'] = __( 'Gray dark outline', 'super-duper' ) . $button_only;
1063
		$theme_colors['outline-indigo']    = __( 'Indigo outline', 'super-duper' ) . $button_only;
1064
		$theme_colors['outline-orange']    = __( 'Orange outline', 'super-duper' ) . $button_only;
1065
	}
1066
1067
	if ( $include_branding ) {
1068
		$theme_colors = $theme_colors + sd_aui_branding_colors();
1069
	}
1070
1071
	if ( $include_translucent ) {
1072
		$button_only                           = $outline_button_only_text ? ' ' . __( '(button only)', 'super-duper' ) : '';
1073
		$theme_colors['translucent-primary']   = __( 'Primary translucent', 'super-duper' ) . $button_only;
1074
		$theme_colors['translucent-secondary'] = __( 'Secondary translucent', 'super-duper' ) . $button_only;
1075
		$theme_colors['translucent-success']   = __( 'Success translucent', 'super-duper' ) . $button_only;
1076
		$theme_colors['translucent-danger']    = __( 'Danger translucent', 'super-duper' ) . $button_only;
1077
		$theme_colors['translucent-warning']   = __( 'Warning translucent', 'super-duper' ) . $button_only;
1078
		$theme_colors['translucent-info']      = __( 'Info translucent', 'super-duper' ) . $button_only;
1079
		$theme_colors['translucent-light']     = __( 'Light translucent', 'super-duper' ) . $button_only;
1080
		$theme_colors['translucent-dark']      = __( 'Dark translucent', 'super-duper' ) . $button_only;
1081
		$theme_colors['translucent-white']     = __( 'White translucent', 'super-duper' ) . $button_only;
1082
		$theme_colors['translucent-purple']    = __( 'Purple translucent', 'super-duper' ) . $button_only;
1083
		$theme_colors['translucent-salmon']    = __( 'Salmon translucent', 'super-duper' ) . $button_only;
1084
		$theme_colors['translucent-cyan']      = __( 'Cyan translucent', 'super-duper' ) . $button_only;
1085
		$theme_colors['translucent-gray']      = __( 'Gray translucent', 'super-duper' ) . $button_only;
1086
		$theme_colors['translucent-gray-dark'] = __( 'Gray dark translucent', 'super-duper' ) . $button_only;
1087
		$theme_colors['translucent-indigo']    = __( 'Indigo translucent', 'super-duper' ) . $button_only;
1088
		$theme_colors['translucent-orange']    = __( 'Orange translucent', 'super-duper' ) . $button_only;
1089
	}
1090
1091
	return apply_filters( 'sd_aui_colors', $theme_colors, $include_outlines, $include_branding );
1092
}
1093
1094
/**
1095
 * Get the AUI branding colors.
1096
 *
1097
 * @return array
1098
 */
1099
function sd_aui_branding_colors() {
1100
	return array(
1101
		'facebook'  => __( 'Facebook', 'super-duper' ),
1102
		'twitter'   => __( 'Twitter', 'super-duper' ),
1103
		'instagram' => __( 'Instagram', 'super-duper' ),
1104
		'linkedin'  => __( 'Linkedin', 'super-duper' ),
1105
		'flickr'    => __( 'Flickr', 'super-duper' ),
1106
		'github'    => __( 'GitHub', 'super-duper' ),
1107
		'youtube'   => __( 'YouTube', 'super-duper' ),
1108
		'wordpress' => __( 'WordPress', 'super-duper' ),
1109
		'google'    => __( 'Google', 'super-duper' ),
1110
		'yahoo'     => __( 'Yahoo', 'super-duper' ),
1111
		'vkontakte' => __( 'Vkontakte', 'super-duper' ),
1112
	);
1113
}
1114
1115
1116
/**
1117
 * A helper function for container class.
1118
 *
1119
 * @param string $type
1120
 * @param array $overwrite
1121
 *
1122
 * @return array
1123
 */
1124
function sd_get_container_class_input( $type = 'container', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1124
function sd_get_container_class_input( /** @scrutinizer ignore-unused */ $type = 'container', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1125
1126
	$options = array(
1127
		'container'       => __( 'container (default)', 'super-duper' ),
1128
		'container-sm'    => 'container-sm',
1129
		'container-md'    => 'container-md',
1130
		'container-lg'    => 'container-lg',
1131
		'container-xl'    => 'container-xl',
1132
		'container-xxl'   => 'container-xxl',
1133
		'container-fluid' => 'container-fluid',
1134
		'row'             => 'row',
1135
		'col'             => 'col',
1136
		'card'            => 'card',
1137
		'card-header'     => 'card-header',
1138
		'card-img-top'    => 'card-img-top',
1139
		'card-body'       => 'card-body',
1140
		'card-footer'     => 'card-footer',
1141
		'list-group'      => 'list-group',
1142
		'list-group-item' => 'list-group-item',
1143
		''                => __( 'no container class', 'super-duper' ),
1144
	);
1145
1146
	$defaults = array(
1147
		'type'     => 'select',
1148
		'title'    => __( 'Type', 'super-duper' ),
1149
		'options'  => $options,
1150
		'default'  => '',
1151
		'desc_tip' => true,
1152
		'group'    => __( 'Container', 'super-duper' ),
1153
	);
1154
1155
	$input = wp_parse_args( $overwrite, $defaults );
1156
1157
	return $input;
1158
}
1159
1160
/**
1161
 * A helper function for position class.
1162
 *
1163
 * @param string $type
1164
 * @param array $overwrite
1165
 *
1166
 * @return array
1167
 */
1168
function sd_get_position_class_input( $type = 'position', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1168
function sd_get_position_class_input( /** @scrutinizer ignore-unused */ $type = 'position', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1169
1170
	$options = array(
1171
		''                  => __( 'Default', 'super-duper' ),
1172
		'position-static'   => 'static',
1173
		'position-relative' => 'relative',
1174
		'position-absolute' => 'absolute',
1175
		'position-fixed'    => 'fixed',
1176
		'position-sticky'   => 'sticky',
1177
		'fixed-top'         => 'fixed-top',
1178
		'fixed-bottom'      => 'fixed-bottom',
1179
		'sticky-top'        => 'sticky-top',
1180
	);
1181
1182
	$defaults = array(
1183
		'type'     => 'select',
1184
		'title'    => __( 'Position', 'super-duper' ),
1185
		'options'  => $options,
1186
		'default'  => '',
1187
		'desc_tip' => true,
1188
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
1189
	);
1190
1191
	$input = wp_parse_args( $overwrite, $defaults );
1192
1193
	return $input;
1194
}
1195
1196
/**
1197
 * @param $type
1198
 * @param $overwrite
1199
 *
1200
 * @return array
1201
 */
1202
function sd_get_absolute_position_input( $type = 'absolute_position', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1202
function sd_get_absolute_position_input( /** @scrutinizer ignore-unused */ $type = 'absolute_position', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1203
1204
	$options = array(
1205
		''              => __( 'Default', 'super-duper' ),
1206
		'top-left'      => 'top-left',
1207
		'top-center'    => 'top-center',
1208
		'top-right'     => 'top-right',
1209
		'center-left'   => 'middle-left',
1210
		'center'        => 'center',
1211
		'center-right'  => 'middle-right',
1212
		'bottom-left'   => 'bottom-left',
1213
		'bottom-center' => 'bottom-center',
1214
		'bottom-right'  => 'bottom-right',
1215
	);
1216
1217
	$defaults = array(
1218
		'type'            => 'select',
1219
		'title'           => __( 'Absolute Position', 'super-duper' ),
1220
		'options'         => $options,
1221
		'default'         => '',
1222
		'desc_tip'        => true,
1223
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1224
		'element_require' => '[%position%]=="position-absolute"',
1225
	);
1226
1227
	$input = wp_parse_args( $overwrite, $defaults );
1228
1229
	return $input;
1230
}
1231
1232
/**
1233
 * A helper function for sticky offset input.
1234
 *
1235
 * @param string $type
1236
 * @param array $overwrite
1237
 *
1238
 * @return array
1239
 */
1240
function sd_get_sticky_offset_input( $type = 'top', $overwrite = array() ) {
1241
1242
	$defaults = array(
1243
		'type'            => 'number',
1244
		'title'           => __( 'Sticky offset', 'super-duper' ),
1245
		//'desc' =>  __( 'Sticky offset', 'super-duper' ),
1246
		'default'         => '',
1247
		'desc_tip'        => true,
1248
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1249
		'element_require' => '[%position%]=="sticky" || [%position%]=="sticky-top"',
1250
	);
1251
1252
	// title
1253
	if ( $type == 'top' ) {
1254
		$defaults['title'] = __( 'Top offset', 'super-duper' );
1255
		$defaults['icon']  = 'box-top';
1256
		$defaults['row']   = array(
1257
			'title' => __( 'Sticky offset', 'super-duper' ),
1258
			'key'   => 'sticky-offset',
1259
			'open'  => true,
1260
			'class' => 'text-center',
1261
		);
1262
	} elseif ( $type == 'bottom' ) {
1263
		$defaults['title'] = __( 'Bottom offset', 'super-duper' );
1264
		$defaults['icon']  = 'box-bottom';
1265
		$defaults['row']   = array(
1266
			'key'   => 'sticky-offset',
1267
			'close' => true,
1268
		);
1269
	}
1270
1271
	$input = wp_parse_args( $overwrite, $defaults );
1272
1273
	return $input;
1274
}
1275
1276
/**
1277
 * A helper function for font size
1278
 *
1279
 * @param string $type
1280
 * @param array $overwrite
1281
 *
1282
 * @return array
1283
 */
1284
function sd_get_font_size_input( $type = 'font_size', $overwrite = array(), $has_custom = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1284
function sd_get_font_size_input( /** @scrutinizer ignore-unused */ $type = 'font_size', $overwrite = array(), $has_custom = false ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1285
	global $aui_bs5;
1286
1287
	$options[] = __( 'Inherit from parent', 'super-duper' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.
Loading history...
1288
	if ( $aui_bs5 ) {
1289
		// responsive font sizes
1290
		$options['fs-base'] = 'fs-base (body default)';
1291
		$options['fs-6']    = 'fs-6';
1292
		$options['fs-5']    = 'fs-5';
1293
		$options['fs-4']    = 'fs-4';
1294
		$options['fs-3']    = 'fs-3';
1295
		$options['fs-2']    = 'fs-2';
1296
		$options['fs-1']    = 'fs-1';
1297
1298
		// custom
1299
		$options['fs-lg']  = 'fs-lg';
1300
		$options['fs-sm']  = 'fs-sm';
1301
		$options['fs-xs']  = 'fs-xs';
1302
		$options['fs-xxs'] = 'fs-xxs';
1303
1304
	}
1305
1306
	$options = $options + array(
1307
			'h6'        => 'h6',
1308
			'h5'        => 'h5',
1309
			'h4'        => 'h4',
1310
			'h3'        => 'h3',
1311
			'h2'        => 'h2',
1312
			'h1'        => 'h1',
1313
			'display-1' => 'display-1',
1314
			'display-2' => 'display-2',
1315
			'display-3' => 'display-3',
1316
			'display-4' => 'display-4',
1317
		);
1318
1319
	if ( $aui_bs5 ) {
1320
		$options['display-5'] = 'display-5';
1321
		$options['display-6'] = 'display-6';
1322
	}
1323
1324
	if ( $has_custom ) {
1325
		$options['custom'] = __( 'Custom size', 'super-duper' );
1326
	}
1327
1328
	$defaults = array(
1329
		'type'     => 'select',
1330
		'title'    => __( 'Font size', 'super-duper' ),
1331
		'options'  => $options,
1332
		'default'  => '',
1333
		'desc_tip' => true,
1334
		'group'    => __( 'Typography', 'super-duper' ),
1335
	);
1336
1337
	$input = wp_parse_args( $overwrite, $defaults );
1338
1339
	return $input;
1340
}
1341
1342
/**
1343
 * A helper function for custom font size.
1344
 *
1345
 * @param string $type
1346
 * @param array $overwrite
1347
 *
1348
 * @return array
1349
 */
1350
function sd_get_font_custom_size_input( $type = 'font_size_custom', $overwrite = array(), $parent_type = '' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1350
function sd_get_font_custom_size_input( /** @scrutinizer ignore-unused */ $type = 'font_size_custom', $overwrite = array(), $parent_type = '' ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1351
1352
	$defaults = array(
1353
		'type'              => 'number',
1354
		'title'             => __( 'Font size (rem)', 'super-duper' ),
1355
		'default'           => '',
1356
		'placeholder'       => '1.25',
1357
		'custom_attributes' => array(
1358
			'step' => '0.1',
1359
			'min'  => '0',
1360
			'max'  => '100',
1361
		),
1362
		'desc_tip'          => true,
1363
		'group'             => __( 'Typography', 'super-duper' ),
1364
	);
1365
1366
	if ( $parent_type ) {
1367
		$defaults['element_require'] = '[%' . $parent_type . '%]=="custom"';
1368
	}
1369
1370
	$input = wp_parse_args( $overwrite, $defaults );
1371
1372
	return $input;
1373
}
1374
1375
/**
1376
 * A helper function for custom font size.
1377
 *
1378
 * @param string $type
1379
 * @param array $overwrite
1380
 *
1381
 * @return array
1382
 */
1383
function sd_get_font_line_height_input( $type = 'font_line_height', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1383
function sd_get_font_line_height_input( /** @scrutinizer ignore-unused */ $type = 'font_line_height', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1384
1385
	$defaults = array(
1386
		'type'              => 'number',
1387
		'title'             => __( 'Font Line Height', 'super-duper' ),
1388
		'default'           => '',
1389
		'placeholder'       => '1.75',
1390
		'custom_attributes' => array(
1391
			'step' => '0.1',
1392
			'min'  => '0',
1393
			'max'  => '100',
1394
		),
1395
		'desc_tip'          => true,
1396
		'group'             => __( 'Typography', 'super-duper' ),
1397
	);
1398
1399
	$input = wp_parse_args( $overwrite, $defaults );
1400
1401
	return $input;
1402
}
1403
1404
/**
1405
 * A helper function for font size inputs.
1406
 *
1407
 * @param string $type
1408
 * @param array $overwrite
1409
 *
1410
 * @return array
1411
 */
1412
function sd_get_font_size_input_group( $type = 'font_size', $overwrite = array(), $overwrite_custom = array() ) {
1413
1414
	$inputs = array();
1415
1416
	if ( $overwrite !== false ) {
0 ignored issues
show
introduced by
The condition $overwrite !== false is always true.
Loading history...
1417
		$inputs[ $type ] = sd_get_font_size_input( $type, $overwrite, true );
1418
	}
1419
1420
	if ( $overwrite_custom !== false ) {
1421
		$custom            = $type . '_custom';
1422
		$inputs[ $custom ] = sd_get_font_custom_size_input( $custom, $overwrite_custom, $type );
1423
	}
1424
1425
	return $inputs;
1426
}
1427
1428
/**
1429
 * A helper function for font weight.
1430
 *
1431
 * @param string $type
1432
 * @param array $overwrite
1433
 *
1434
 * @return array
1435
 */
1436
function sd_get_font_weight_input( $type = 'font_weight', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1436
function sd_get_font_weight_input( /** @scrutinizer ignore-unused */ $type = 'font_weight', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1437
1438
	$options = array(
1439
		''                                => __( 'Inherit', 'super-duper' ),
1440
		'font-weight-bold'                => 'bold',
1441
		'font-weight-bolder'              => 'bolder',
1442
		'font-weight-normal'              => 'normal',
1443
		'font-weight-light'               => 'light',
1444
		'font-weight-lighter'             => 'lighter',
1445
		'font-italic'                     => 'italic',
1446
		'font-weight-bold font-italic'    => 'bold italic',
1447
		'font-weight-bolder font-italic'  => 'bolder italic',
1448
		'font-weight-normal font-italic'  => 'normal italic',
1449
		'font-weight-light font-italic'   => 'light italic',
1450
		'font-weight-lighter font-italic' => 'lighter italic',
1451
	);
1452
1453
	$defaults = array(
1454
		'type'     => 'select',
1455
		'title'    => __( 'Appearance', 'super-duper' ),
1456
		'options'  => $options,
1457
		'default'  => '',
1458
		'desc_tip' => true,
1459
		'group'    => __( 'Typography', 'super-duper' ),
1460
	);
1461
1462
	$input = wp_parse_args( $overwrite, $defaults );
1463
1464
	return $input;
1465
}
1466
1467
/**
1468
 * A helper function for font case class.
1469
 *
1470
 * @param $type
1471
 * @param $overwrite
1472
 *
1473
 * @return array
1474
 */
1475
function sd_get_font_case_input( $type = 'font_weight', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1475
function sd_get_font_case_input( /** @scrutinizer ignore-unused */ $type = 'font_weight', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1476
1477
	$options = array(
1478
		''                => __( 'Default', 'super-duper' ),
1479
		'text-lowercase'  => __( 'lowercase', 'super-duper' ),
1480
		'text-uppercase'  => __( 'UPPERCASE', 'super-duper' ),
1481
		'text-capitalize' => __( 'Capitalize', 'super-duper' ),
1482
	);
1483
1484
	$defaults = array(
1485
		'type'     => 'select',
1486
		'title'    => __( 'Letter case', 'super-duper' ),
1487
		'options'  => $options,
1488
		'default'  => '',
1489
		'desc_tip' => true,
1490
		'group'    => __( 'Typography', 'super-duper' ),
1491
	);
1492
1493
	$input = wp_parse_args( $overwrite, $defaults );
1494
1495
	return $input;
1496
}
1497
1498
/**
1499
 * @param string $type
1500
 * @param array $overwrite
1501
 *
1502
 * @return array
1503
 * @todo remove this as now included above.
1504
 * A helper function for font size
1505
 *
1506
 */
1507
function sd_get_font_italic_input( $type = 'font_italic', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1507
function sd_get_font_italic_input( /** @scrutinizer ignore-unused */ $type = 'font_italic', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1508
1509
	$options = array(
1510
		''            => __( 'No', 'super-duper' ),
1511
		'font-italic' => __( 'Yes', 'super-duper' ),
1512
	);
1513
1514
	$defaults = array(
1515
		'type'     => 'select',
1516
		'title'    => __( 'Font italic', 'super-duper' ),
1517
		'options'  => $options,
1518
		'default'  => '',
1519
		'desc_tip' => true,
1520
		'group'    => __( 'Typography', 'super-duper' ),
1521
	);
1522
1523
	$input = wp_parse_args( $overwrite, $defaults );
1524
1525
	return $input;
1526
}
1527
1528
/**
1529
 * A helper function for the anchor input.
1530
 *
1531
 * @param $type
1532
 * @param $overwrite
1533
 *
1534
 * @return array
1535
 */
1536
function sd_get_anchor_input( $type = 'anchor', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1536
function sd_get_anchor_input( /** @scrutinizer ignore-unused */ $type = 'anchor', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1537
1538
	$defaults = array(
1539
		'type'     => 'text',
1540
		'title'    => __( 'HTML anchor', 'super-duper' ),
1541
		'desc'     => __( 'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.', 'super-duper' ),
1542
		'default'  => '',
1543
		'desc_tip' => true,
1544
		'group'    => __( 'Advanced', 'super-duper' ),
1545
	);
1546
1547
	$input = wp_parse_args( $overwrite, $defaults );
1548
1549
	return $input;
1550
}
1551
1552
/**
1553
 * A helper function for the class input.
1554
 *
1555
 * @param $type
1556
 * @param $overwrite
1557
 *
1558
 * @return array
1559
 */
1560
function sd_get_class_input( $type = 'css_class', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1560
function sd_get_class_input( /** @scrutinizer ignore-unused */ $type = 'css_class', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1561
1562
	$defaults = array(
1563
		'type'     => 'text',
1564
		'title'    => __( 'Additional CSS class(es)', 'super-duper' ),
1565
		'desc'     => __( 'Separate multiple classes with spaces.', 'super-duper' ),
1566
		'default'  => '',
1567
		'desc_tip' => true,
1568
		'group'    => __( 'Advanced', 'super-duper' ),
1569
	);
1570
1571
	$input = wp_parse_args( $overwrite, $defaults );
1572
1573
	return $input;
1574
}
1575
1576
/**
1577
 * A helper function for font size inputs.
1578
 *
1579
 * @param string $type
1580
 * @param array $overwrite
1581
 *
1582
 * @return array
1583
 */
1584
function sd_get_hover_animations_input( $type = 'hover_animations', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1584
function sd_get_hover_animations_input( /** @scrutinizer ignore-unused */ $type = 'hover_animations', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1585
1586
	$options = array(
1587
		''                 => __( 'none', 'super-duper' ),
1588
		'hover-zoom'       => __( 'Zoom', 'super-duper' ),
1589
		'hover-shadow'     => __( 'Shadow', 'super-duper' ),
1590
		'hover-move-up'    => __( 'Move up', 'super-duper' ),
1591
		'hover-move-down'  => __( 'Move down', 'super-duper' ),
1592
		'hover-move-left'  => __( 'Move left', 'super-duper' ),
1593
		'hover-move-right' => __( 'Move right', 'super-duper' ),
1594
	);
1595
1596
	$defaults = array(
1597
		'type'     => 'select',
1598
		'multiple' => true,
1599
		'title'    => __( 'Hover Animations', 'super-duper' ),
1600
		'options'  => $options,
1601
		'default'  => '',
1602
		'desc_tip' => true,
1603
		'group'    => __( 'Hover Animations', 'super-duper' ),
1604
	);
1605
1606
	$input = wp_parse_args( $overwrite, $defaults );
1607
1608
	return $input;
1609
}
1610
1611
1612
function sd_get_flex_align_items_input( $type = 'align-items', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1612
function sd_get_flex_align_items_input( /** @scrutinizer ignore-unused */ $type = 'align-items', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1613
	$device_size = '';
1614
	if ( ! empty( $overwrite['device_type'] ) ) {
1615
		if ( $overwrite['device_type'] == 'Tablet' ) {
1616
			$device_size = '-md';
1617
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1618
			$device_size = '-lg';
1619
		}
1620
	}
1621
	$options = array(
1622
		''                                         => __( 'Default', 'super-duper' ),
1623
		'align-items' . $device_size . '-start'    => 'align-items-start',
1624
		'align-items' . $device_size . '-end'      => 'align-items-end',
1625
		'align-items' . $device_size . '-center'   => 'align-items-center',
1626
		'align-items' . $device_size . '-baseline' => 'align-items-baseline',
1627
		'align-items' . $device_size . '-stretch'  => 'align-items-stretch',
1628
	);
1629
1630
	$defaults = array(
1631
		'type'            => 'select',
1632
		'title'           => __( 'Vertical Align Items', 'super-duper' ),
1633
		'options'         => $options,
1634
		'default'         => '',
1635
		'desc_tip'        => true,
1636
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1637
		'element_require' => ' ( ( [%container%]=="row" ) || ( [%display%]=="d-flex" || [%display_md%]=="d-md-flex" || [%display_lg%]=="d-lg-flex" ) ) ',
1638
1639
	);
1640
1641
	$input = wp_parse_args( $overwrite, $defaults );
1642
1643
	return $input;
1644
}
1645
1646
function sd_get_flex_align_items_input_group( $type = 'flex_align_items', $overwrite = array() ) {
1647
	$inputs = array();
1648
	$sizes  = array(
1649
		''    => 'Mobile',
1650
		'_md' => 'Tablet',
1651
		'_lg' => 'Desktop',
1652
	);
1653
1654
	if ( $overwrite !== false ) {
1655
1656
		foreach ( $sizes as $ds => $dt ) {
1657
			$overwrite['device_type'] = $dt;
1658
			$inputs[ $type . $ds ]    = sd_get_flex_align_items_input( $type, $overwrite );
1659
		}
1660
	}
1661
1662
	return $inputs;
1663
}
1664
1665
function sd_get_flex_justify_content_input( $type = 'flex_justify_content', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1665
function sd_get_flex_justify_content_input( /** @scrutinizer ignore-unused */ $type = 'flex_justify_content', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1666
	$device_size = '';
1667
	if ( ! empty( $overwrite['device_type'] ) ) {
1668
		if ( $overwrite['device_type'] == 'Tablet' ) {
1669
			$device_size = '-md';
1670
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1671
			$device_size = '-lg';
1672
		}
1673
	}
1674
	$options = array(
1675
		''                                            => __( 'Default', 'super-duper' ),
1676
		'justify-content' . $device_size . '-start'   => 'justify-content-start',
1677
		'justify-content' . $device_size . '-end'     => 'justify-content-end',
1678
		'justify-content' . $device_size . '-center'  => 'justify-content-center',
1679
		'justify-content' . $device_size . '-between' => 'justify-content-between',
1680
		'justify-content' . $device_size . '-stretch' => 'justify-content-around',
1681
	);
1682
1683
	$defaults = array(
1684
		'type'            => 'select',
1685
		'title'           => __( 'Justify content', 'super-duper' ),
1686
		'options'         => $options,
1687
		'default'         => '',
1688
		'desc_tip'        => true,
1689
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1690
		'element_require' => '( ( [%container%]=="row" ) || ( [%display%]=="d-flex" || [%display_md%]=="d-md-flex" || [%display_lg%]=="d-lg-flex" ) ) ',
1691
1692
	);
1693
1694
	$input = wp_parse_args( $overwrite, $defaults );
1695
1696
	return $input;
1697
}
1698
1699
function sd_get_flex_justify_content_input_group( $type = 'flex_justify_content', $overwrite = array() ) {
1700
	$inputs = array();
1701
	$sizes  = array(
1702
		''    => 'Mobile',
1703
		'_md' => 'Tablet',
1704
		'_lg' => 'Desktop',
1705
	);
1706
1707
	if ( $overwrite !== false ) {
1708
1709
		foreach ( $sizes as $ds => $dt ) {
1710
			$overwrite['device_type'] = $dt;
1711
			$inputs[ $type . $ds ]    = sd_get_flex_justify_content_input( $type, $overwrite );
1712
		}
1713
	}
1714
1715
	return $inputs;
1716
}
1717
1718
1719
function sd_get_flex_align_self_input( $type = 'flex_align_self', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1719
function sd_get_flex_align_self_input( /** @scrutinizer ignore-unused */ $type = 'flex_align_self', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1720
	$device_size = '';
1721
	if ( ! empty( $overwrite['device_type'] ) ) {
1722
		if ( $overwrite['device_type'] == 'Tablet' ) {
1723
			$device_size = '-md';
1724
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1725
			$device_size = '-lg';
1726
		}
1727
	}
1728
	$options = array(
1729
		''                                         => __( 'Default', 'super-duper' ),
1730
		'align-items' . $device_size . '-start'    => 'align-items-start',
1731
		'align-items' . $device_size . '-end'      => 'align-items-end',
1732
		'align-items' . $device_size . '-center'   => 'align-items-center',
1733
		'align-items' . $device_size . '-baseline' => 'align-items-baseline',
1734
		'align-items' . $device_size . '-stretch'  => 'align-items-stretch',
1735
	);
1736
1737
	$defaults = array(
1738
		'type'            => 'select',
1739
		'title'           => __( 'Align Self', 'super-duper' ),
1740
		'options'         => $options,
1741
		'default'         => '',
1742
		'desc_tip'        => true,
1743
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1744
		'element_require' => ' [%container%]=="col" ',
1745
1746
	);
1747
1748
	$input = wp_parse_args( $overwrite, $defaults );
1749
1750
	return $input;
1751
}
1752
1753
function sd_get_flex_align_self_input_group( $type = 'flex_align_self', $overwrite = array() ) {
1754
	$inputs = array();
1755
	$sizes  = array(
1756
		''    => 'Mobile',
1757
		'_md' => 'Tablet',
1758
		'_lg' => 'Desktop',
1759
	);
1760
1761
	if ( $overwrite !== false ) {
1762
1763
		foreach ( $sizes as $ds => $dt ) {
1764
			$overwrite['device_type'] = $dt;
1765
			$inputs[ $type . $ds ]    = sd_get_flex_align_self_input( $type, $overwrite );
1766
		}
1767
	}
1768
1769
	return $inputs;
1770
}
1771
1772
function sd_get_flex_order_input( $type = 'flex_order', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1772
function sd_get_flex_order_input( /** @scrutinizer ignore-unused */ $type = 'flex_order', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1773
	$device_size = '';
1774
	if ( ! empty( $overwrite['device_type'] ) ) {
1775
		if ( $overwrite['device_type'] == 'Tablet' ) {
1776
			$device_size = '-md';
1777
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1778
			$device_size = '-lg';
1779
		}
1780
	}
1781
	$options = array(
1782
		'' => __( 'Default', 'super-duper' ),
1783
	);
1784
1785
	$i = 0;
1786
	while ( $i <= 5 ) {
1787
		$options[ 'order' . $device_size . '-' . $i ] = $i;
1788
		$i++;
1789
	}
1790
1791
	$defaults = array(
1792
		'type'            => 'select',
1793
		'title'           => __( 'Flex Order', 'super-duper' ),
1794
		'options'         => $options,
1795
		'default'         => '',
1796
		'desc_tip'        => true,
1797
		'group'           => __( 'Wrapper Styles', 'super-duper' ),
1798
		'element_require' => ' [%container%]=="col" ',
1799
1800
	);
1801
1802
	$input = wp_parse_args( $overwrite, $defaults );
1803
1804
	return $input;
1805
}
1806
1807
function sd_get_flex_order_input_group( $type = 'flex_order', $overwrite = array() ) {
1808
	$inputs = array();
1809
	$sizes  = array(
1810
		''    => 'Mobile',
1811
		'_md' => 'Tablet',
1812
		'_lg' => 'Desktop',
1813
	);
1814
1815
	if ( $overwrite !== false ) {
1816
1817
		foreach ( $sizes as $ds => $dt ) {
1818
			$overwrite['device_type'] = $dt;
1819
			$inputs[ $type . $ds ]    = sd_get_flex_order_input( $type, $overwrite );
1820
		}
1821
	}
1822
1823
	return $inputs;
1824
}
1825
1826
function sd_get_flex_wrap_group( $type = 'flex_wrap', $overwrite = array() ) {
1827
	$inputs = array();
1828
	$sizes  = array(
1829
		''    => 'Mobile',
1830
		'_md' => 'Tablet',
1831
		'_lg' => 'Desktop',
1832
	);
1833
1834
	if ( $overwrite !== false ) {
1835
1836
		foreach ( $sizes as $ds => $dt ) {
1837
			$overwrite['device_type'] = $dt;
1838
			$inputs[ $type . $ds ]    = sd_get_flex_wrap_input( $type, $overwrite );
1839
		}
1840
	}
1841
1842
	return $inputs;
1843
}
1844
1845
function sd_get_flex_wrap_input( $type = 'flex_wrap', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1845
function sd_get_flex_wrap_input( /** @scrutinizer ignore-unused */ $type = 'flex_wrap', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1846
	$device_size = '';
1847
	if ( ! empty( $overwrite['device_type'] ) ) {
1848
		if ( $overwrite['device_type'] == 'Tablet' ) {
1849
			$device_size = '-md';
1850
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1851
			$device_size = '-lg';
1852
		}
1853
	}
1854
	$options = array(
1855
		''                                      => __( 'Default', 'super-duper' ),
1856
		'flex' . $device_size . '-nowrap'       => 'nowrap',
1857
		'flex' . $device_size . '-wrap'         => 'wrap',
1858
		'flex' . $device_size . '-wrap-reverse' => 'wrap-reverse',
1859
	);
1860
1861
	$defaults = array(
1862
		'type'     => 'select',
1863
		'title'    => __( 'Flex wrap', 'super-duper' ),
1864
		'options'  => $options,
1865
		'default'  => '',
1866
		'desc_tip' => true,
1867
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
1868
	);
1869
1870
	$input = wp_parse_args( $overwrite, $defaults );
1871
1872
	return $input;
1873
}
1874
1875
function sd_get_float_group( $type = 'float', $overwrite = array() ) {
1876
	$inputs = array();
1877
	$sizes  = array(
1878
		''    => 'Mobile',
1879
		'_md' => 'Tablet',
1880
		'_lg' => 'Desktop',
1881
	);
1882
1883
	if ( $overwrite !== false ) {
1884
1885
		foreach ( $sizes as $ds => $dt ) {
1886
			$overwrite['device_type'] = $dt;
1887
			$inputs[ $type . $ds ]    = sd_get_float_input( $type, $overwrite );
1888
		}
1889
	}
1890
1891
	return $inputs;
1892
}
1893
function sd_get_float_input( $type = 'float', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1893
function sd_get_float_input( /** @scrutinizer ignore-unused */ $type = 'float', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1894
	$device_size = '';
1895
	if ( ! empty( $overwrite['device_type'] ) ) {
1896
		if ( $overwrite['device_type'] == 'Tablet' ) {
1897
			$device_size = '-md';
1898
		} elseif ( $overwrite['device_type'] == 'Desktop' ) {
1899
			$device_size = '-lg';
1900
		}
1901
	}
1902
	$options = array(
1903
		''                                      => __( 'Default', 'super-duper' ),
1904
		'float' . $device_size . '-start'       => 'left',
1905
		'float' . $device_size . '-end'         => 'right',
1906
		'float' . $device_size . '-none' => 'none',
1907
	);
1908
1909
	$defaults = array(
1910
		'type'     => 'select',
1911
		'title'    => __( 'Float', 'super-duper' ),
1912
		'options'  => $options,
1913
		'default'  => '',
1914
		'desc_tip' => true,
1915
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
1916
	);
1917
1918
	$input = wp_parse_args( $overwrite, $defaults );
1919
1920
	return $input;
1921
}
1922
1923
/**
1924
 * @param $type
1925
 * @param $overwrite
1926
 *
1927
 * @return array
1928
 */
1929
function sd_get_zindex_input( $type = 'zindex', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1929
function sd_get_zindex_input( /** @scrutinizer ignore-unused */ $type = 'zindex', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1930
1931
	$options = array(
1932
		''          => __( 'Default', 'super-duper' ),
1933
		'zindex-0'  => '0',
1934
		'zindex-1'  => '1',
1935
		'zindex-5'  => '5',
1936
		'zindex-10' => '10',
1937
	);
1938
1939
	$defaults = array(
1940
		'type'     => 'select',
1941
		'title'    => __( 'Z-index', 'super-duper' ),
1942
		'options'  => $options,
1943
		'default'  => '',
1944
		'desc_tip' => true,
1945
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
1946
	);
1947
1948
	$input = wp_parse_args( $overwrite, $defaults );
1949
1950
	return $input;
1951
}
1952
1953
/**
1954
 * @param $type
1955
 * @param $overwrite
1956
 *
1957
 * @return array
1958
 */
1959
function sd_get_overflow_input( $type = 'overflow', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1959
function sd_get_overflow_input( /** @scrutinizer ignore-unused */ $type = 'overflow', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1960
1961
	$options = array(
1962
		''                 => __( 'Default', 'super-duper' ),
1963
		'overflow-auto'    => __( 'Auto', 'super-duper' ),
1964
		'overflow-hidden'  => __( 'Hidden', 'super-duper' ),
1965
		'overflow-visible' => __( 'Visible', 'super-duper' ),
1966
		'overflow-scroll'  => __( 'Scroll', 'super-duper' ),
1967
	);
1968
1969
	$defaults = array(
1970
		'type'     => 'select',
1971
		'title'    => __( 'Overflow', 'super-duper' ),
1972
		'options'  => $options,
1973
		'default'  => '',
1974
		'desc_tip' => true,
1975
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
1976
	);
1977
1978
	$input = wp_parse_args( $overwrite, $defaults );
1979
1980
	return $input;
1981
}
1982
1983
/**
1984
 * @param $type
1985
 * @param $overwrite
1986
 *
1987
 * @return array
1988
 */
1989
function sd_get_max_height_input( $type = 'max_height', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1989
function sd_get_max_height_input( /** @scrutinizer ignore-unused */ $type = 'max_height', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1990
1991
	$defaults = array(
1992
		'type'        => 'text',
1993
		'title'       => __( 'Max height', 'super-duper' ),
1994
		'value'       => '',
1995
		'default'     => '',
1996
		'placeholder' => '',
1997
		'desc_tip'    => true,
1998
		'group'       => __( 'Wrapper Styles', 'super-duper' ),
1999
	);
2000
2001
	$input = wp_parse_args( $overwrite, $defaults );
2002
2003
	return $input;
2004
}
2005
2006
/**
2007
 * @param $type
2008
 * @param $overwrite
2009
 *
2010
 * @return array
2011
 */
2012
function sd_get_scrollbars_input( $type = 'scrollbars', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2012
function sd_get_scrollbars_input( /** @scrutinizer ignore-unused */ $type = 'scrollbars', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2013
2014
	$options = array(
2015
		''               => __( 'Default', 'super-duper' ),
2016
		'scrollbars-ios' => __( 'IOS Style', 'super-duper' ),
2017
	);
2018
2019
	$defaults = array(
2020
		'type'     => 'select',
2021
		'title'    => __( 'Scrollbars', 'super-duper' ),
2022
		'options'  => $options,
2023
		'default'  => '',
2024
		'desc_tip' => true,
2025
		'group'    => __( 'Wrapper Styles', 'super-duper' ),
2026
	);
2027
2028
	$input = wp_parse_args( $overwrite, $defaults );
2029
2030
	return $input;
2031
}
2032
2033
/**
2034
 * Build AUI classes from settings.
2035
 *
2036
 * @param $args
2037
 *
2038
 * @return string
2039
 * @todo find best way to use px- py- or general p-
2040
 */
2041
function sd_build_aui_class( $args ) {
2042
	global $aui_bs5;
2043
2044
	$classes = array();
2045
2046
	if ( $aui_bs5 ) {
2047
		$p_ml = 'ms-';
2048
		$p_mr = 'me-';
2049
2050
		$p_pl = 'ps-';
2051
		$p_pr = 'pe-';
2052
	} else {
2053
		$p_ml = 'ml-';
2054
		$p_mr = 'mr-';
2055
2056
		$p_pl = 'pl-';
2057
		$p_pr = 'pr-';
2058
	}
2059
2060
	// margins.
2061
	if ( isset( $args['mt'] ) && $args['mt'] !== '' ) {
2062
		$classes[] = 'mt-' . sanitize_html_class( $args['mt'] );
2063
		$mt        = $args['mt'];
2064
	} else {
2065
		$mt = null;
2066
	}
2067
	if ( isset( $args['mr'] ) && $args['mr'] !== '' ) {
2068
		$classes[] = $p_mr . sanitize_html_class( $args['mr'] );
2069
		$mr        = $args['mr'];
2070
	} else {
2071
		$mr = null;
2072
	}
2073
	if ( isset( $args['mb'] ) && $args['mb'] !== '' ) {
2074
		$classes[] = 'mb-' . sanitize_html_class( $args['mb'] );
2075
		$mb        = $args['mb'];
2076
	} else {
2077
		$mb = null;
2078
	}
2079
	if ( isset( $args['ml'] ) && $args['ml'] !== '' ) {
2080
		$classes[] = $p_ml . sanitize_html_class( $args['ml'] );
2081
		$ml        = $args['ml'];
2082
	} else {
2083
		$ml = null;
2084
	}
2085
2086
	// margins tablet.
2087
	if ( isset( $args['mt_md'] ) && $args['mt_md'] !== '' ) {
2088
		$classes[] = 'mt-md-' . sanitize_html_class( $args['mt_md'] );
2089
		$mt_md     = $args['mt_md'];
2090
	} else {
2091
		$mt_md = null;
2092
	}
2093
	if ( isset( $args['mr_md'] ) && $args['mr_md'] !== '' ) {
2094
		$classes[] = $p_mr . 'md-' . sanitize_html_class( $args['mr_md'] );
2095
		$mt_md     = $args['mr_md'];
2096
	} else {
2097
		$mr_md = null;
2098
	}
2099
	if ( isset( $args['mb_md'] ) && $args['mb_md'] !== '' ) {
2100
		$classes[] = 'mb-md-' . sanitize_html_class( $args['mb_md'] );
2101
		$mt_md     = $args['mb_md'];
2102
	} else {
2103
		$mb_md = null;
2104
	}
2105
	if ( isset( $args['ml_md'] ) && $args['ml_md'] !== '' ) {
2106
		$classes[] = $p_ml . 'md-' . sanitize_html_class( $args['ml_md'] );
2107
		$mt_md     = $args['ml_md'];
2108
	} else {
2109
		$ml_md = null;
2110
	}
2111
2112
	// margins desktop.
2113
	if ( isset( $args['mt_lg'] ) && $args['mt_lg'] !== '' ) {
2114
		if ( $mt == null && $mt_md == null ) {
2115
			$classes[] = 'mt-' . sanitize_html_class( $args['mt_lg'] );
2116
		} else {
2117
			$classes[] = 'mt-lg-' . sanitize_html_class( $args['mt_lg'] );
2118
		}
2119
	}
2120
	if ( isset( $args['mr_lg'] ) && $args['mr_lg'] !== '' ) {
2121
		if ( $mr == null && $mr_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mr_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2122
			$classes[] = $p_mr . sanitize_html_class( $args['mr_lg'] );
2123
		} else {
2124
			$classes[] = $p_mr . 'lg-' . sanitize_html_class( $args['mr_lg'] );
2125
		}
2126
	}
2127
	if ( isset( $args['mb_lg'] ) && $args['mb_lg'] !== '' ) {
2128
		if ( $mb == null && $mb_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mb_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2129
			$classes[] = 'mb-' . sanitize_html_class( $args['mb_lg'] );
2130
		} else {
2131
			$classes[] = 'mb-lg-' . sanitize_html_class( $args['mb_lg'] );
2132
		}
2133
	}
2134
	if ( isset( $args['ml_lg'] ) && $args['ml_lg'] !== '' ) {
2135
		if ( $ml == null && $ml_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ml_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2136
			$classes[] = $p_ml . sanitize_html_class( $args['ml_lg'] );
2137
		} else {
2138
			$classes[] = $p_ml . 'lg-' . sanitize_html_class( $args['ml_lg'] );
2139
		}
2140
	}
2141
2142
	// padding.
2143
	if ( isset( $args['pt'] ) && $args['pt'] !== '' ) {
2144
		$classes[] = 'pt-' . sanitize_html_class( $args['pt'] );
2145
		$pt        = $args['pt'];
2146
	} else {
2147
		$pt = null;
2148
	}
2149
	if ( isset( $args['pr'] ) && $args['pr'] !== '' ) {
2150
		$classes[] = $p_pr . sanitize_html_class( $args['pr'] );
2151
		$pr        = $args['pr'];
2152
	} else {
2153
		$pr = null;
2154
	}
2155
	if ( isset( $args['pb'] ) && $args['pb'] !== '' ) {
2156
		$classes[] = 'pb-' . sanitize_html_class( $args['pb'] );
2157
		$pb        = $args['pb'];
2158
	} else {
2159
		$pb = null;
2160
	}
2161
	if ( isset( $args['pl'] ) && $args['pl'] !== '' ) {
2162
		$classes[] = $p_pl . sanitize_html_class( $args['pl'] );
2163
		$pl        = $args['pl'];
2164
	} else {
2165
		$pl = null;
2166
	}
2167
2168
	// padding tablet.
2169
	if ( isset( $args['pt_md'] ) && $args['pt_md'] !== '' ) {
2170
		$classes[] = 'pt-md-' . sanitize_html_class( $args['pt_md'] );
2171
		$pt_md     = $args['pt_md'];
2172
	} else {
2173
		$pt_md = null;
2174
	}
2175
	if ( isset( $args['pr_md'] ) && $args['pr_md'] !== '' ) {
2176
		$classes[] = $p_pr . 'md-' . sanitize_html_class( $args['pr_md'] );
2177
		$pt_md     = $args['pr_md'];
2178
	} else {
2179
		$pr_md = null;
2180
	}
2181
	if ( isset( $args['pb_md'] ) && $args['pb_md'] !== '' ) {
2182
		$classes[] = 'pb-md-' . sanitize_html_class( $args['pb_md'] );
2183
		$pt_md     = $args['pb_md'];
2184
	} else {
2185
		$pb_md = null;
2186
	}
2187
	if ( isset( $args['pl_md'] ) && $args['pl_md'] !== '' ) {
2188
		$classes[] = $p_pl . 'md-' . sanitize_html_class( $args['pl_md'] );
2189
		$pt_md     = $args['pl_md'];
2190
	} else {
2191
		$pl_md = null;
2192
	}
2193
2194
	// padding desktop.
2195
	if ( isset( $args['pt_lg'] ) && $args['pt_lg'] !== '' ) {
2196
		if ( $pt == null && $pt_md == null ) {
2197
			$classes[] = 'pt-' . sanitize_html_class( $args['pt_lg'] );
2198
		} else {
2199
			$classes[] = 'pt-lg-' . sanitize_html_class( $args['pt_lg'] );
2200
		}
2201
	}
2202
	if ( isset( $args['pr_lg'] ) && $args['pr_lg'] !== '' ) {
2203
		if ( $pr == null && $pr_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pr_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2204
			$classes[] = $p_pr . sanitize_html_class( $args['pr_lg'] );
2205
		} else {
2206
			$classes[] = $p_pr . 'lg-' . sanitize_html_class( $args['pr_lg'] );
2207
		}
2208
	}
2209
	if ( isset( $args['pb_lg'] ) && $args['pb_lg'] !== '' ) {
2210
		if ( $pb == null && $pb_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pb_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2211
			$classes[] = 'pb-' . sanitize_html_class( $args['pb_lg'] );
2212
		} else {
2213
			$classes[] = 'pb-lg-' . sanitize_html_class( $args['pb_lg'] );
2214
		}
2215
	}
2216
	if ( isset( $args['pl_lg'] ) && $args['pl_lg'] !== '' ) {
2217
		if ( $pl == null && $pl_md == null ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pl_md does not seem to be defined for all execution paths leading up to this point.
Loading history...
2218
			$classes[] = $p_pl . sanitize_html_class( $args['pl_lg'] );
2219
		} else {
2220
			$classes[] = $p_pl . 'lg-' . sanitize_html_class( $args['pl_lg'] );
2221
		}
2222
	}
2223
2224
	// row cols, mobile, tablet, desktop
2225
	if ( ! empty( $args['row_cols'] ) && $args['row_cols'] !== '' ) {
2226
		$classes[] = sanitize_html_class( 'row-cols-' . $args['row_cols'] );
2227
		$row_cols  = $args['row_cols'];
2228
	} else {
2229
		$row_cols = null;
2230
	}
2231
	if ( ! empty( $args['row_cols_md'] ) && $args['row_cols_md'] !== '' ) {
2232
		$classes[]   = sanitize_html_class( 'row-cols-md-' . $args['row_cols_md'] );
2233
		$row_cols_md = $args['row_cols_md'];
2234
	} else {
2235
		$row_cols_md = null;
2236
	}
2237
	if ( ! empty( $args['row_cols_lg'] ) && $args['row_cols_lg'] !== '' ) {
2238
		if ( $row_cols == null && $row_cols_md == null ) {
2239
			$classes[] = sanitize_html_class( 'row-cols-' . $args['row_cols_lg'] );
2240
		} else {
2241
			$classes[] = sanitize_html_class( 'row-cols-lg-' . $args['row_cols_lg'] );
2242
		}
2243
	}
2244
2245
	// columns , mobile, tablet, desktop
2246
	if ( ! empty( $args['col'] ) && $args['col'] !== '' ) {
2247
		$classes[] = sanitize_html_class( 'col-' . $args['col'] );
2248
		$col       = $args['col'];
2249
	} else {
2250
		$col = null;
2251
	}
2252
	if ( ! empty( $args['col_md'] ) && $args['col_md'] !== '' ) {
2253
		$classes[] = sanitize_html_class( 'col-md-' . $args['col_md'] );
2254
		$col_md    = $args['col_md'];
2255
	} else {
2256
		$col_md = null;
2257
	}
2258
	if ( ! empty( $args['col_lg'] ) && $args['col_lg'] !== '' ) {
2259
		if ( $col == null && $col_md == null ) {
2260
			$classes[] = sanitize_html_class( 'col-' . $args['col_lg'] );
2261
		} else {
2262
			$classes[] = sanitize_html_class( 'col-lg-' . $args['col_lg'] );
2263
		}
2264
	}
2265
2266
	// border
2267
	if ( isset( $args['border'] ) && ( $args['border'] == 'none' || $args['border'] === '0' || $args['border'] === 0 ) ) {
2268
		$classes[] = 'border-0';
2269
	} elseif ( ! empty( $args['border'] ) ) {
2270
		$border_class = 'border';
2271
		if ( ! empty( $args['border_type'] ) && strpos( $args['border_type'], '-0' ) === false ) {
2272
			$border_class = '';
2273
		}
2274
		$classes[] = $border_class . ' border-' . sanitize_html_class( $args['border'] );
2275
	}
2276
2277
	// border radius type
2278
	if ( ! empty( $args['rounded'] ) ) {
2279
		$classes[] = sanitize_html_class( $args['rounded'] );
2280
	}
2281
2282
	// border radius size BS4
2283
	if ( isset( $args['rounded_size'] ) && in_array( $args['rounded_size'], array( 'sm', 'lg' ) ) ) {
2284
		$classes[] = 'rounded-' . sanitize_html_class( $args['rounded_size'] );
2285
		// if we set a size then we need to remove "rounded" if set
2286
		if ( ( $key = array_search( 'rounded', $classes ) ) !== false ) {
2287
			unset( $classes[ $key ] );
2288
		}
2289
	} else {
2290
2291
		// border radius size , mobile, tablet, desktop
2292
		if ( isset( $args['rounded_size'] ) && $args['rounded_size'] !== '' ) {
2293
			$classes[]    = sanitize_html_class( 'rounded-' . $args['rounded_size'] );
2294
			$rounded_size = $args['rounded_size'];
2295
		} else {
2296
			$rounded_size = null;
2297
		}
2298
		if ( isset( $args['rounded_size_md'] ) && $args['rounded_size_md'] !== '' ) {
2299
			$classes[]       = sanitize_html_class( 'rounded-md-' . $args['rounded_size_md'] );
2300
			$rounded_size_md = $args['rounded_size_md'];
2301
		} else {
2302
			$rounded_size_md = null;
2303
		}
2304
		if ( isset( $args['rounded_size_lg'] ) && $args['rounded_size_lg'] !== '' ) {
2305
			if ( $rounded_size == null && $rounded_size_md == null ) {
2306
				$classes[] = sanitize_html_class( 'rounded-' . $args['rounded_size_lg'] );
2307
			} else {
2308
				$classes[] = sanitize_html_class( 'rounded-lg-' . $args['rounded_size_lg'] );
2309
			}
2310
		}
2311
	}
2312
2313
	// shadow
2314
	//if ( !empty( $args['shadow'] ) ) { $classes[] = sanitize_html_class($args['shadow']); }
2315
2316
	// background
2317
	if ( ! empty( $args['bg'] ) ) {
2318
		$classes[] = 'bg-' . sanitize_html_class( $args['bg'] );
2319
	}
2320
2321
	// text_color
2322
	if ( ! empty( $args['text_color'] ) ) {
2323
		$classes[] = 'text-' . sanitize_html_class( $args['text_color'] );
2324
	}
2325
2326
	// text_align
2327
	if ( ! empty( $args['text_justify'] ) ) {
2328
		$classes[] = 'text-justify';
2329
	} else {
2330
		if ( ! empty( $args['text_align'] ) ) {
2331
			$classes[]  = sanitize_html_class( $args['text_align'] );
2332
			$text_align = $args['text_align'];
2333
		} else {
2334
			$text_align = null;
2335
		}
2336
		if ( ! empty( $args['text_align_md'] ) && $args['text_align_md'] !== '' ) {
2337
			$classes[]     = sanitize_html_class( $args['text_align_md'] );
2338
			$text_align_md = $args['text_align_md'];
2339
		} else {
2340
			$text_align_md = null;
2341
		}
2342
		if ( ! empty( $args['text_align_lg'] ) && $args['text_align_lg'] !== '' ) {
2343
			if ( $text_align == null && $text_align_md == null ) {
2344
				$classes[] = sanitize_html_class( str_replace( '-lg', '', $args['text_align_lg'] ) );
2345
			} else {
2346
				$classes[] = sanitize_html_class( $args['text_align_lg'] );
2347
			}
2348
		}
2349
	}
2350
2351
	// display
2352
	if ( ! empty( $args['display'] ) ) {
2353
		$classes[] = sanitize_html_class( $args['display'] );
2354
		$display   = $args['display'];
2355
	} else {
2356
		$display = null;
2357
	}
2358
	if ( ! empty( $args['display_md'] ) && $args['display_md'] !== '' ) {
2359
		$classes[]  = sanitize_html_class( $args['display_md'] );
2360
		$display_md = $args['display_md'];
2361
	} else {
2362
		$display_md = null;
2363
	}
2364
	if ( ! empty( $args['display_lg'] ) && $args['display_lg'] !== '' ) {
2365
		if ( $display == null && $display_md == null ) {
2366
			$classes[] = sanitize_html_class( str_replace( '-lg', '', $args['display_lg'] ) );
2367
		} else {
2368
			$classes[] = sanitize_html_class( $args['display_lg'] );
2369
		}
2370
	}
2371
2372
	// bgtus - background transparent until scroll
2373
	if ( ! empty( $args['bgtus'] ) ) {
2374
		$classes[] = sanitize_html_class( 'bg-transparent-until-scroll' );
2375
	}
2376
2377
	// cscos - change color scheme on scroll
2378
	if ( ! empty( $args['bgtus'] ) && ! empty( $args['cscos'] ) ) {
2379
		$classes[] = sanitize_html_class( 'color-scheme-flip-on-scroll' );
2380
	}
2381
2382
	// hover animations
2383
	if ( ! empty( $args['hover_animations'] ) ) {
2384
		$classes[] = sd_sanitize_html_classes( str_replace( ',', ' ', $args['hover_animations'] ) );
2385
	}
2386
2387
	// absolute_position
2388
	if ( ! empty( $args['absolute_position'] ) ) {
2389
		if ( 'top-left' === $args['absolute_position'] ) {
2390
			$classes[] = 'start-0 top-0';
2391
		} elseif ( 'top-center' === $args['absolute_position'] ) {
2392
			$classes[] = 'start-50 top-0 translate-middle';
2393
		} elseif ( 'top-right' === $args['absolute_position'] ) {
2394
			$classes[] = 'end-0 top-0';
2395
		} elseif ( 'center-left' === $args['absolute_position'] ) {
2396
			$classes[] = 'start-0 top-50';
2397
		} elseif ( 'center' === $args['absolute_position'] ) {
2398
			$classes[] = 'start-50 top-50 translate-middle';
2399
		} elseif ( 'center-right' === $args['absolute_position'] ) {
2400
			$classes[] = 'end-0 top-50';
2401
		} elseif ( 'bottom-left' === $args['absolute_position'] ) {
2402
			$classes[] = 'start-0 bottom-0';
2403
		} elseif ( 'bottom-center' === $args['absolute_position'] ) {
2404
			$classes[] = 'start-50 bottom-0 translate-middle';
2405
		} elseif ( 'bottom-right' === $args['absolute_position'] ) {
2406
			$classes[] = 'end-0 bottom-0';
2407
		}
2408
	}
2409
2410
	// build classes from build keys
2411
	$build_keys = sd_get_class_build_keys();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $build_keys is correct as sd_get_class_build_keys() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
2412
	if ( ! empty( $build_keys ) ) {
2413
		foreach ( $build_keys as $key ) {
0 ignored issues
show
Bug introduced by
The expression $build_keys of type void is not traversable.
Loading history...
2414
2415
			if ( substr( $key, -4 ) == '-MTD' ) {
2416
2417
				$k = str_replace( '-MTD', '', $key );
2418
2419
				// Mobile, Tablet, Desktop
2420
				if ( ! empty( $args[ $k ] ) && $args[ $k ] !== '' ) {
2421
					$classes[] = sanitize_html_class( $args[ $k ] );
2422
					$v         = $args[ $k ];
2423
				} else {
2424
					$v = null;
2425
				}
2426
				if ( ! empty( $args[ $k . '_md' ] ) && $args[ $k . '_md' ] !== '' ) {
2427
					$classes[] = sanitize_html_class( $args[ $k . '_md' ] );
2428
					$v_md      = $args[ $k . '_md' ];
2429
				} else {
2430
					$v_md = null;
2431
				}
2432
				if ( ! empty( $args[ $k . '_lg' ] ) && $args[ $k . '_lg' ] !== '' ) {
2433
					if ( $v == null && $v_md == null ) {
2434
						$classes[] = sanitize_html_class( str_replace( '-lg', '', $args[ $k . '_lg' ] ) );
2435
					} else {
2436
						$classes[] = sanitize_html_class( $args[ $k . '_lg' ] );
2437
					}
2438
				}
2439
			} else {
2440
				if ( $key == 'font_size' && ! empty( $args[ $key ] ) && $args[ $key ] == 'custom' ) {
2441
					continue;
2442
				}
2443
				if ( ! empty( $args[ $key ] ) ) {
2444
					$classes[] = sd_sanitize_html_classes( $args[ $key ] );
2445
				}
2446
			}
2447
		}
2448
	}
2449
2450
	return implode( ' ', $classes );
2451
}
2452
2453
/**
2454
 * Build Style output from arguments.
2455
 *
2456
 * @param $args
2457
 *
2458
 * @return array
2459
 */
2460
function sd_build_aui_styles( $args ) {
2461
2462
	$styles = array();
2463
2464
	// background color
2465
	if ( ! empty( $args['bg'] ) && $args['bg'] !== '' ) {
2466
		if ( $args['bg'] == 'custom-color' ) {
2467
			$styles['background-color'] = $args['bg_color'];
2468
		} elseif ( $args['bg'] == 'custom-gradient' ) {
2469
			$styles['background-image'] = $args['bg_gradient'];
2470
2471
			// use background on text.
2472
			if ( ! empty( $args['bg_on_text'] ) && $args['bg_on_text'] ) {
2473
				$styles['background-clip']         = 'text';
2474
				$styles['-webkit-background-clip'] = 'text';
2475
				$styles['text-fill-color']         = 'transparent';
2476
				$styles['-webkit-text-fill-color'] = 'transparent';
2477
			}
2478
		}
2479
	}
2480
2481
	if ( ! empty( $args['bg_image'] ) && $args['bg_image'] !== '' ) {
2482
		$hasImage = true;
2483
		if ( ! empty( $styles['background-color'] ) && $args['bg'] == 'custom-color' ) {
2484
			$styles['background-image']      = 'url(' . $args['bg_image'] . ')';
2485
			$styles['background-blend-mode'] = 'overlay';
2486
		} elseif ( ! empty( $styles['background-image'] ) && $args['bg'] == 'custom-gradient' ) {
2487
			$styles['background-image'] .= ',url(' . $args['bg_image'] . ')';
2488
		} elseif ( ! empty( $args['bg'] ) && $args['bg'] != '' && $args['bg'] != 'transparent' ) {
2489
			// do nothing as we alreay have a preset
2490
			$hasImage = false;
2491
		} else {
2492
			$styles['background-image'] = 'url(' . $args['bg_image'] . ')';
2493
		}
2494
2495
		if ( $hasImage ) {
2496
			$styles['background-size'] = 'cover';
2497
2498
			if ( ! empty( $args['bg_image_fixed'] ) && $args['bg_image_fixed'] ) {
2499
				$styles['background-attachment'] = 'fixed';
2500
			}
2501
		}
2502
2503
		if ( $hasImage && ! empty( $args['bg_image_xy'] ) && ! empty( $args['bg_image_xy']['x'] ) ) {
2504
			$styles['background-position'] = ( $args['bg_image_xy']['x'] * 100 ) . '% ' . ( $args['bg_image_xy']['y'] * 100 ) . '%';
2505
		}
2506
	}
2507
2508
	// sticky offset top
2509
	if ( ! empty( $args['sticky_offset_top'] ) && $args['sticky_offset_top'] !== '' ) {
2510
		$styles['top'] = absint( $args['sticky_offset_top'] );
2511
	}
2512
2513
	// sticky offset bottom
2514
	if ( ! empty( $args['sticky_offset_bottom'] ) && $args['sticky_offset_bottom'] !== '' ) {
2515
		$styles['bottom'] = absint( $args['sticky_offset_bottom'] );
2516
	}
2517
2518
	// font size
2519
	if ( ! empty( $args['font_size_custom'] ) && $args['font_size_custom'] !== '' ) {
2520
		$styles['font-size'] = (float) $args['font_size_custom'] . 'rem';
2521
	}
2522
2523
	// font color
2524
	if ( ! empty( $args['text_color_custom'] ) && $args['text_color_custom'] !== '' ) {
2525
		$styles['color'] = esc_attr( $args['text_color_custom'] );
2526
	}
2527
2528
	// font line height
2529
	if ( ! empty( $args['font_line_height'] ) && $args['font_line_height'] !== '' ) {
2530
		$styles['line-height'] = esc_attr( $args['font_line_height'] );
2531
	}
2532
2533
	// max height
2534
	if ( ! empty( $args['max_height'] ) && $args['max_height'] !== '' ) {
2535
		$styles['max-height'] = esc_attr( $args['max_height'] );
2536
	}
2537
2538
	$style_string = '';
2539
	if ( ! empty( $styles ) ) {
2540
		foreach ( $styles as $key => $val ) {
2541
			$style_string .= esc_attr( $key ) . ':' . esc_attr( $val ) . ';';
2542
		}
2543
	}
2544
2545
	return $style_string;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $style_string returns the type string which is incompatible with the documented return type array.
Loading history...
2546
2547
}
2548
2549
/**
2550
 * Build the hover styles from args.
2551
 *
2552
 * @param $args
2553
 * @param $is_preview
2554
 *
2555
 * @return string
2556
 */
2557
function sd_build_hover_styles( $args, $is_preview = false ) {
2558
	$rules = '';
2559
	// text color
2560
	if ( ! empty( $args['styleid'] ) ) {
2561
		$styleid = $is_preview ? 'html .editor-styles-wrapper .' . esc_attr( $args['styleid'] ) : 'html .' . esc_attr( $args['styleid'] );
2562
2563
		// text
2564
		if ( ! empty( $args['text_color_hover'] ) ) {
2565
			$key    = 'custom' === $args['text_color_hover'] && ! empty( $args['text_color_hover_custom'] ) ? 'text_color_hover_custom' : 'text_color_hover';
2566
			$color  = sd_get_color_from_var( $args[ $key ] );
2567
			$rules .= $styleid . ':hover {color: ' . $color . ' !important;} ';
2568
		}
2569
2570
		// bg
2571
		if ( ! empty( $args['bg_hover'] ) ) {
2572
			if ( 'custom-gradient' === $args['bg_hover'] ) {
2573
				$color  = $args['bg_hover_gradient'];
2574
				$rules .= $styleid . ':hover {background-image: ' . $color . ' !important;} ';
2575
				$rules .= $styleid . '.btn:hover {border-color: transparent !important;} ';
2576
			} else {
2577
				$key    = 'custom-color' === $args['bg_hover'] ? 'bg_hover_color' : 'bg_hover';
2578
				$color  = sd_get_color_from_var( $args[ $key ] );
2579
				$rules .= $styleid . ':hover {background: ' . $color . ' !important;} ';
2580
				$rules .= $styleid . '.btn:hover {border-color: ' . $color . ' !important;} ';
2581
			}
2582
		}
2583
	}
2584
2585
	return $rules ? '<style>' . $rules . '</style>' : '';
2586
}
2587
2588
/**
2589
 * Try to get a CSS color varibale for a given value.
2590
 *
2591
 * @param $var
2592
 *
2593
 * @return mixed|string
2594
 */
2595
function sd_get_color_from_var( $var ) {
2596
2597
	//sanitize_hex_color() @todo this does not cover transparency
2598
	if ( strpos( $var, '#' ) === false ) {
2599
		$var = defined( 'BLOCKSTRAP_BLOCKS_VERSION' ) ? 'var(--wp--preset--color--' . esc_attr( $var ) . ')' : 'var(--' . esc_attr( $var ) . ')';
2600
	}
2601
2602
	return $var;
2603
}
2604
2605
/**
2606
 * Sanitize single or multiple HTML classes.
2607
 *
2608
 * @param $classes
2609
 * @param $sep
2610
 *
2611
 * @return string
2612
 */
2613
function sd_sanitize_html_classes( $classes, $sep = ' ' ) {
2614
	$return = '';
2615
2616
	if ( ! is_array( $classes ) ) {
2617
		$classes = explode( $sep, $classes );
2618
	}
2619
2620
	if ( ! empty( $classes ) ) {
2621
		foreach ( $classes as $class ) {
2622
			$return .= sanitize_html_class( $class ) . ' ';
2623
		}
2624
	}
2625
2626
	return $return;
2627
}
2628
2629
2630
/**
2631
 * Keys that are used for the class builder.
2632
 *
2633
 * @return void
2634
 */
2635
function sd_get_class_build_keys() {
2636
	$keys = array(
2637
		'container',
2638
		'position',
2639
		'flex_direction',
2640
		'shadow',
2641
		'rounded',
2642
		'nav_style',
2643
		'horizontal_alignment',
2644
		'nav_fill',
2645
		'width',
2646
		'font_weight',
2647
		'font_size',
2648
		'font_case',
2649
		'css_class',
2650
		'flex_align_items-MTD',
2651
		'flex_justify_content-MTD',
2652
		'flex_align_self-MTD',
2653
		'flex_order-MTD',
2654
		'styleid',
2655
		'border_opacity',
2656
		'border_width',
2657
		'border_type',
2658
		'opacity',
2659
		'zindex',
2660
		'flex_wrap-MTD',
2661
		'h100',
2662
		'overflow',
2663
		'scrollbars',
2664
		'float-MTD'
2665
	);
2666
2667
	return apply_filters( 'sd_class_build_keys', $keys );
0 ignored issues
show
Bug Best Practice introduced by
The expression return apply_filters('sd...ass_build_keys', $keys) also could return the type array<integer,string> which is incompatible with the documented return type void.
Loading history...
2668
}
2669
2670
/**
2671
 * This is a placeholder function for the visibility conditions input.
2672
 *
2673
 * @param $type
2674
 * @param $overwrite
2675
 *
2676
 * @return array
2677
 */
2678
function sd_get_visibility_conditions_input( $type = 'visibility_conditions', $overwrite = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2678
function sd_get_visibility_conditions_input( /** @scrutinizer ignore-unused */ $type = 'visibility_conditions', $overwrite = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2679
	$defaults = array(
2680
		'type'         => 'visibility_conditions',
2681
		'title'        => __( 'Block Visibility', 'super-duper' ),
2682
		'button_title' => __( 'Set Block Visibility', 'super-duper' ),
2683
		'default'      => '',
2684
		'desc_tip'     => true,
2685
		'group'        => __( 'Visibility Conditions', 'super-duper' ),
2686
	);
2687
2688
	$input = wp_parse_args( $overwrite, $defaults );
2689
2690
	return $input;
2691
}
2692
2693
/**
2694
 * Get a array of user roles.
2695
 *
2696
 *
2697
 *
2698
 * @param array $exclude An array of roles to exclude from the return array.
2699
 * @return array An array of roles.
2700
 */
2701
function sd_user_roles_options( $exclude = array() ) {
2702
	$user_roles = array();
2703
2704
	if ( !function_exists('get_editable_roles') ) {
2705
		require_once( ABSPATH . '/wp-admin/includes/user.php' );
2706
	}
2707
2708
	$roles = get_editable_roles();
2709
2710
	foreach ( $roles as $role => $data ) {
2711
		if ( ! ( ! empty( $exclude ) && in_array( $role, $exclude ) ) ) {
2712
			$user_roles[ esc_attr( $role ) ] = translate_user_role( $data['name'] );
2713
		}
2714
	}
2715
2716
	return apply_filters( 'sd_user_roles_options', $user_roles );
2717
}
2718
2719
/**
2720
 * Get visibility conditions rule options.
2721
 *
2722
 *
2723
 *
2724
 * @return array Rule options.
2725
 */
2726
function sd_visibility_rules_options() {
2727
	$options = array(
2728
		'logged_in'  => __( 'Logged In', 'super-duper' ),
2729
		'logged_out' => __( 'Logged Out', 'super-duper' ),
2730
		'user_roles' => __( 'Specific User Roles', 'super-duper' )
2731
	);
2732
2733
	if ( class_exists( 'GeoDirectory' ) ) {
2734
		$options['gd_field'] = __( 'GD Field', 'super-duper' );
2735
	}
2736
2737
	return apply_filters( 'sd_visibility_rules_options', $options );
2738
}
2739
2740
/**
2741
 * Get visibility GD field options.
2742
 *
2743
 * @return array
2744
 */
2745
function sd_visibility_gd_field_options(){
2746
	$fields = geodir_post_custom_fields( '', 'all', 'all', 'none' );
0 ignored issues
show
Bug introduced by
The function geodir_post_custom_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2746
	$fields = /** @scrutinizer ignore-call */ geodir_post_custom_fields( '', 'all', 'all', 'none' );
Loading history...
2747
2748
	$keys = array();
2749
	if ( ! empty( $fields ) ) {
2750
		foreach( $fields as $field ) {
2751
			if ( apply_filters( 'geodir_badge_field_skip_key', false, $field ) ) {
2752
				continue;
2753
			}
2754
2755
			$keys[ $field['htmlvar_name'] ] = $field['htmlvar_name'] . ' ( ' . __( $field['admin_title'], 'geodirectory' ) . ' )';
2756
2757
			// Extra address fields
2758
			if ( $field['htmlvar_name'] == 'address' && ( $address_fields = geodir_post_meta_address_fields( '' ) ) ) {
0 ignored issues
show
Bug introduced by
The function geodir_post_meta_address_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2758
			if ( $field['htmlvar_name'] == 'address' && ( $address_fields = /** @scrutinizer ignore-call */ geodir_post_meta_address_fields( '' ) ) ) {
Loading history...
2759
				foreach ( $address_fields as $_field => $args ) {
2760
					if ( $_field != 'map_directions' && $_field != 'street' ) {
2761
						$keys[ $_field ] = $_field . ' ( ' . $args['frontend_title'] . ' )';
2762
					}
2763
				}
2764
			}
2765
		}
2766
	}
2767
2768
	$keys['post_date'] = 'post_date ( ' . __( 'post date', 'geodirectory' ) . ' )';
2769
	$keys['post_modified'] = 'post_modified ( ' . __( 'post modified', 'geodirectory' ) . ' )';
2770
	$keys['default_category'] = 'default_category ( ' . __( 'Default Category', 'geodirectory' ) . ' )';
2771
	$keys['post_id'] = 'post_id ( ' . __( 'post id', 'geodirectory' ) . ' )';
2772
	$keys['post_status'] = 'post_status ( ' . __( 'Post Status', 'geodirectory' ) . ' )';
2773
2774
	$options = apply_filters( 'geodir_badge_field_keys', $keys );
2775
2776
	return apply_filters( 'sd_visibility_gd_field_options', $options );
2777
}
2778
2779
/**
2780
 * Get visibility field conditions options.
2781
 *
2782
 * @return array
2783
 */
2784
function sd_visibility_field_condition_options(){
2785
	$options = array(
2786
		'is_empty' => __( 'is empty', 'super-duper' ),
2787
		'is_not_empty' => __( 'is not empty', 'super-duper' ),
2788
		'is_equal' => __( 'is equal', 'super-duper' ),
2789
		'is_not_equal' => __( 'is not equal', 'super-duper' ),
2790
		'is_greater_than' => __( 'is greater than', 'super-duper' ),
2791
		'is_less_than' => __( 'is less than', 'super-duper' ),
2792
		'is_contains' => __( 'is contains', 'super-duper' ),
2793
		'is_not_contains' => __( 'is not contains', 'super-duper' ),
2794
	);
2795
2796
	return apply_filters( 'sd_visibility_field_condition_options', $options );
2797
}
2798
2799
/**
2800
 * Get visibility conditions output options.
2801
 *
2802
 *
2803
 *
2804
 * @return array Template type options.
2805
 */
2806
function sd_visibility_output_options() {
2807
	$options = array(
2808
		'hide'          => __( 'Hide Block', 'super-duper' ),
2809
		'message'       => __( 'Show Custom Message', 'super-duper' ),
2810
		'page'          => __( 'Show Page Content', 'super-duper' ),
2811
		'template_part' => __( 'Show Template Part', 'super-duper' ),
2812
	);
2813
2814
	return apply_filters( 'sd_visibility_output_options', $options );
2815
}
2816
2817
/**
2818
 * Get the template page options.
2819
 *
2820
 *
2821
 *
2822
 * @param array $args Array of arguments.
2823
 * @return array Template page options.
2824
 */
2825
function sd_template_page_options( $args = array() ) {
2826
	global $sd_tmpl_page_options;
2827
2828
	if ( ! empty( $sd_tmpl_page_options ) ) {
2829
		return $sd_tmpl_page_options;
2830
	}
2831
2832
	$args = wp_parse_args( $args, array(
2833
		'child_of'    => 0,
2834
		'sort_column' => 'post_title',
2835
		'sort_order'  => 'ASC'
2836
	) );
2837
2838
	$exclude_pages = array();
2839
	if ( $page_on_front = get_option( 'page_on_front' ) ) {
2840
		$exclude_pages[] = $page_on_front;
2841
	}
2842
2843
	if ( $page_for_posts = get_option( 'page_for_posts' ) ) {
2844
		$exclude_pages[] = $page_for_posts;
2845
	}
2846
2847
	if ( ! empty( $exclude_pages ) ) {
2848
		$args['exclude'] = $exclude_pages;
2849
	}
2850
2851
	$pages = get_pages( $args );
2852
2853
	$options = array( '' => __( 'Select Page...', 'super-duper' ) );
2854
	if ( ! empty( $pages ) ) {
2855
		foreach ( $pages as $page ) {
2856
			if ( ! empty( $page->ID ) && ! empty( $page->post_title ) ) {
2857
				$options[ $page->ID ] = $page->post_title . ' (#' . $page->ID . ')';
2858
			}
2859
		}
2860
	}
2861
2862
	$sd_tmpl_page_options = $options;
2863
2864
	return apply_filters( 'sd_template_page_options', $options );
2865
}
2866
2867
/**
2868
 * Get the template part options.
2869
 *
2870
 *
2871
 *
2872
 * @param array $args Array of arguments.
2873
 * @return array Template part options.
2874
 */
2875
function sd_template_part_options( $args = array() ) {
2876
	global $sd_tmpl_part_options;
2877
2878
	if ( ! empty( $sd_tmpl_part_options ) ) {
2879
		return $sd_tmpl_part_options;
2880
	}
2881
2882
	$options = array( '' => __( 'Select Template Part...', 'super-duper' ) );
2883
2884
	$parts = get_block_templates( array(), 'wp_template_part' );
2885
2886
	if ( ! empty( $parts ) ) {
2887
		foreach ( $parts as $part ) {
2888
			$options[ $part->slug ] = $part->title . ' (#' . $part->slug . ')';
2889
		}
2890
	}
2891
2892
	$sd_tmpl_part_options = $options;
2893
2894
	return apply_filters( 'sd_template_part_options', $options, $args );
2895
}
2896
2897
/**
2898
 * Get the template part by slug.
2899
 *
2900
 *
2901
 *
2902
 * @param string $slug Template slug.
2903
 * @return array Template part object.
2904
 */
2905
function sd_get_template_part_by_slug( $slug ) {
2906
	global $bs_tmpl_part_by_slug;
2907
2908
	if ( empty( $bs_tmpl_part_by_slug ) ) {
2909
		$bs_tmpl_part_by_slug = array();
2910
	}
2911
2912
	if ( isset( $bs_tmpl_part_by_slug[ $slug ] ) ) {
2913
		return $bs_tmpl_part_by_slug[ $slug ];
2914
	}
2915
2916
	$template_query = get_block_templates( array( 'slug__in' => array( $slug ) ), 'wp_template_part' );
2917
2918
	$query_post = ! empty( $template_query ) ? $template_query[0] : array();
2919
2920
	$template_part = ! empty( $query_post ) && $query_post->status == 'publish' ? $query_post : array();
2921
2922
	$bs_tmpl_part_by_slug[ $slug ] = $template_part;
2923
2924
	return apply_filters( 'sd_get_template_part_by_slug', $template_part, $slug );
2925
}
2926
2927
/**
2928
 * Filters the content of a single block.
2929
 *
2930
 *
2931
 *
2932
 * @param string   $block_content The block content.
2933
 * @param array    $block         The full block, including name and attributes.
2934
 * @param WP_Block $instance      The block instance.
2935
 */
2936
function sd_render_block( $block_content, $block, $instance ) {
2937
	// No block visibility conditions set.
2938
	if ( empty( $block['attrs']['visibility_conditions'] ) ) {
2939
		return $block_content;
2940
	}
2941
2942
	$attributes = json_decode( $block['attrs']['visibility_conditions'], true );
2943
	$rules = ! empty( $attributes ) ? sd_block_parse_rules( $attributes ) : array();
2944
2945
	// No rules set.
2946
	if ( empty( $rules ) ) {
2947
		return $block_content;
2948
	}
2949
2950
	$_block_content = $block_content;
2951
2952
	if ( ! empty( $rules ) && sd_block_check_rules( $rules ) ) {
2953
		if ( ! empty( $attributes['output']['type'] ) ) {
2954
			switch ( $attributes['output']['type'] ) {
2955
				case 'hide':
2956
					$valid_type = true;
2957
					$content = '';
2958
2959
					break;
2960
				case 'message':
2961
					$valid_type = true;
2962
2963
					if ( isset( $attributes['output']['message'] ) ) {
2964
						$content = $attributes['output']['message'] != '' ? __( stripslashes( $attributes['output']['message'] ), 'super-duper' ) : $attributes['output']['message'];
2965
2966
						if ( ! empty( $attributes['output']['message_type'] ) ) {
2967
							$content = aui()->alert( array(
2968
									'type'=> $attributes['output']['message_type'],
2969
									'content'=> $content
2970
								)
2971
							);
2972
						}
2973
					}
2974
2975
					break;
2976
				case 'page':
2977
					$valid_type = true;
2978
2979
					$page_id = ! empty( $attributes['output']['page'] ) ? absint( $attributes['output']['page'] ) : 0;
2980
					$content = sd_get_page_content( $page_id );
2981
2982
					break;
2983
				case 'template_part':
2984
					$valid_type = true;
2985
2986
					$template_part = ! empty( $attributes['output']['template_part'] ) ? $attributes['output']['template_part'] : '';
2987
					$content = sd_get_template_part_content( $template_part );
2988
2989
					break;
2990
				default:
2991
					$valid_type = false;
2992
					break;
2993
			}
2994
2995
			if ( $valid_type ) {
2996
				$block_content = '<div class="' . esc_attr( wp_get_block_default_classname( $instance->name ) ) . ' sd-block-has-rule">' . $content . '</div>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $content does not seem to be defined for all execution paths leading up to this point.
Loading history...
2997
			}
2998
		}
2999
	}
3000
3001
	return apply_filters( 'sd_render_block_visibility_content', $block_content, $_block_content, $attributes, $block, $instance );
3002
}
3003
add_filter( 'render_block', 'sd_render_block', 9, 3 );
3004
3005
function sd_get_page_content( $page_id ) {
3006
	$content = $page_id > 0 ? get_post_field( 'post_content', (int) $page_id ) : '';
3007
3008
	// Maybe bypass content
3009
	$bypass_content = apply_filters( 'sd_bypass_page_content', '', $content, $page_id );
3010
	if ( $bypass_content ) {
3011
		return $bypass_content;
3012
	}
3013
3014
	// Run the shortcodes on the content.
3015
	$content = do_shortcode( $content );
3016
3017
	// Run block content if its available.
3018
	if ( function_exists( 'do_blocks' ) ) {
3019
		$content = do_blocks( $content );
3020
	}
3021
3022
	return apply_filters( 'sd_get_page_content', $content, $page_id );
3023
}
3024
3025
function sd_get_template_part_content( $template_part ) {
3026
	$template_part_post = $template_part ? sd_get_template_part_by_slug( $template_part ) : array();
3027
	$content = ! empty( $template_part_post ) ? $template_part_post->content : '';
3028
3029
	// Maybe bypass content
3030
	$bypass_content = apply_filters( 'sd_bypass_template_part_content', '', $content, $template_part );
3031
	if ( $bypass_content ) {
3032
		return $bypass_content;
3033
	}
3034
3035
	// Run the shortcodes on the content.
3036
	$content = do_shortcode( $content );
3037
3038
	// Run block content if its available.
3039
	if ( function_exists( 'do_blocks' ) ) {
3040
		$content = do_blocks( $content );
3041
	}
3042
3043
	return apply_filters( 'sd_get_template_part_content', $content, $template_part );
3044
}
3045
3046
function sd_block_parse_rules( $attrs ) {
3047
	$rules = array();
3048
3049
	if ( ! empty( $attrs ) && is_array( $attrs ) ) {
3050
		$attrs_keys = array_keys( $attrs );
3051
3052
		for ( $i = 1; $i <= count( $attrs_keys ); $i++ ) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
3053
			if ( ! empty( $attrs[ 'rule' . $i ] ) && is_array( $attrs[ 'rule' . $i ] ) ) {
3054
				$rules[] = $attrs[ 'rule' . $i ];
3055
			}
3056
		}
3057
	}
3058
3059
	return apply_filters( 'sd_block_parse_rules', $rules, $attrs );
3060
}
3061
3062
function sd_block_check_rules( $rules ) {
3063
	if ( ! ( is_array( $rules ) && ! empty( $rules ) ) ) {
3064
		return true;
3065
	}
3066
3067
	foreach ( $rules as $key => $rule ) {
3068
		$match = apply_filters( 'sd_block_check_rule', true, $rule );
3069
3070
		if ( ! $match ) {
3071
			break;
3072
		}
3073
	}
3074
3075
	return apply_filters( 'sd_block_check_rules', $match, $rules );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $match seems to be defined by a foreach iteration on line 3067. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
3076
}
3077
3078
function sd_block_check_rule( $match, $rule ) {
3079
	if ( $match && ! empty( $rule['type'] ) ) {
3080
		switch ( $rule['type'] ) {
3081
			case 'logged_in':
3082
				$match = (bool) is_user_logged_in();
3083
3084
				break;
3085
			case 'logged_out':
3086
				$match = ! is_user_logged_in();
3087
3088
				break;
3089
			case 'user_roles':
3090
				$match = false;
3091
3092
				if ( ! empty( $rule['user_roles'] ) ) {
3093
					$user_roles = is_scalar( $rule['user_roles'] ) ? explode( ",", $rule['user_roles'] ) : $rule['user_roles'];
3094
3095
					if ( is_array( $user_roles ) ) {
3096
						$user_roles = array_filter( array_map( 'trim', $user_roles ) );
3097
					}
3098
3099
					if ( ! empty( $user_roles ) && is_array( $user_roles ) && is_user_logged_in() && ( $current_user = wp_get_current_user() ) ) {
3100
						$current_user_roles = $current_user->roles;
3101
3102
						foreach ( $user_roles as $role ) {
3103
							if ( in_array( $role, $current_user_roles ) ) {
3104
								$match = true;
3105
							}
3106
						}
3107
					}
3108
				}
3109
3110
				break;
3111
			case 'gd_field':
3112
				$match = sd_block_check_rule_gd_field( $rule );
3113
3114
				break;
3115
		}
3116
	}
3117
3118
	return $match;
3119
}
3120
add_filter( 'sd_block_check_rule', 'sd_block_check_rule', 10, 2 );
3121
3122
function sd_block_check_rule_gd_field( $rule ) {
3123
	global $gd_post;
3124
3125
	$match_found = false;
3126
3127
	if ( class_exists( 'GeoDirectory' ) && ! empty( $gd_post->ID ) && ! empty( $rule['field'] ) && ! empty( $rule['condition'] ) ) {
3128
		$args['block_visibility'] = true;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
3129
		$args['key'] = $rule['field'];
3130
		$args['condition'] = $rule['condition'];
3131
		$args['search'] = isset( $rule['search'] ) ? $rule['search'] : '';
3132
3133
		if ( $args['key'] == 'street' ) {
3134
			$args['key'] = 'address';
3135
		}
3136
3137
		$match_field = $_match_field = $args['key'];
3138
3139
		if ( $match_field == 'address' ) {
3140
			$match_field = 'street';
3141
		} elseif ( $match_field == 'post_images' ) {
3142
			$match_field = 'featured_image';
3143
		}
3144
3145
		$find_post = $gd_post;
3146
		$find_post_keys = ! empty( $find_post ) ? array_keys( (array) $find_post ) : array();
3147
3148
		if ( ! empty( $find_post->ID ) && ! in_array( 'post_category', $find_post_keys ) ) {
3149
			$find_post = geodir_get_post_info( (int) $find_post->ID );
0 ignored issues
show
Bug introduced by
The function geodir_get_post_info was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

3149
			$find_post = /** @scrutinizer ignore-call */ geodir_get_post_info( (int) $find_post->ID );
Loading history...
3150
			$find_post_keys = ! empty( $find_post ) ? array_keys( (array) $find_post ) : array();
3151
		}
3152
3153
		if ( $match_field === '' || ( ! empty( $find_post_keys ) && ( in_array( $match_field, $find_post_keys ) || in_array( $_match_field, $find_post_keys ) ) ) ) {
3154
			$address_fields = array( 'street2', 'neighbourhood', 'city', 'region', 'country', 'zip', 'latitude', 'longitude' ); // Address fields
3155
			$field = array();
3156
3157
			if ( $match_field && ! in_array( $match_field, array( 'post_date', 'post_modified', 'default_category', 'post_id', 'post_status' ) ) && ! in_array( $match_field, $address_fields ) ) {
3158
				$package_id = geodir_get_post_package_id( $find_post->ID, $find_post->post_type );
0 ignored issues
show
Bug introduced by
The function geodir_get_post_package_id was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

3158
				$package_id = /** @scrutinizer ignore-call */ geodir_get_post_package_id( $find_post->ID, $find_post->post_type );
Loading history...
3159
				$fields = geodir_post_custom_fields( $package_id, 'all', $find_post->post_type, 'none' );
0 ignored issues
show
Bug introduced by
The function geodir_post_custom_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

3159
				$fields = /** @scrutinizer ignore-call */ geodir_post_custom_fields( $package_id, 'all', $find_post->post_type, 'none' );
Loading history...
3160
3161
				foreach ( $fields as $field_info ) {
3162
					if ( $match_field == $field_info['htmlvar_name'] ) {
3163
						$field = $field_info;
3164
						break;
3165
					} elseif( $_match_field == $field_info['htmlvar_name'] ) {
3166
						$field = $field_info;
3167
						break;
3168
					}
3169
				}
3170
3171
				if ( empty( $field ) ) {
3172
					return false;
3173
				}
3174
			}
3175
3176
			$search = $args['search'];
3177
3178
			// Address fields.
3179
			if ( in_array( $match_field, $address_fields ) && ( $address_fields = geodir_post_meta_address_fields( '' ) ) ) {
0 ignored issues
show
Bug introduced by
The function geodir_post_meta_address_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

3179
			if ( in_array( $match_field, $address_fields ) && ( $address_fields = /** @scrutinizer ignore-call */ geodir_post_meta_address_fields( '' ) ) ) {
Loading history...
3180
				if ( ! empty( $address_fields[ $match_field ] ) ) {
3181
					$field = $address_fields[ $match_field ];
3182
				}
3183
			}
3184
3185
			$is_date = ( ! empty( $field['type'] ) && $field['type'] == 'datepicker' ) || in_array( $match_field, array( 'post_date', 'post_modified' ) ) ? true : false;
3186
			$is_date = apply_filters( 'geodir_post_badge_is_date', $is_date, $match_field, $field, $args, $find_post );
0 ignored issues
show
Unused Code introduced by
The assignment to $is_date is dead and can be removed.
Loading history...
3187
3188
			$match_value = isset($find_post->{$match_field}) ? esc_attr( trim( $find_post->{$match_field} ) ) : '';
3189
			$match_found = $match_field === '' ? true : false;
3190
3191
			if ( ! $match_found ) {
3192
				if ( ( $match_field == 'post_date' || $match_field == 'post_modified' ) && ( empty( $args['condition'] ) || $args['condition'] == 'is_greater_than' || $args['condition'] == 'is_less_than' ) ) {
3193
					if ( strpos( $search, '+' ) === false && strpos( $search, '-' ) === false ) {
3194
						$search = '+' . $search;
3195
					}
3196
					$the_time = $match_field == 'post_modified' ? get_the_modified_date( 'Y-m-d', $find_post ) : get_the_time( 'Y-m-d', $find_post );
3197
					$until_time = strtotime( $the_time . ' ' . $search . ' days' );
0 ignored issues
show
Bug introduced by
Are you sure $the_time of type false|integer|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

3197
					$until_time = strtotime( /** @scrutinizer ignore-type */ $the_time . ' ' . $search . ' days' );
Loading history...
3198
					$now_time   = strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) );
3199
					if ( ( empty( $args['condition'] ) || $args['condition'] == 'is_less_than' ) && $until_time > $now_time ) {
3200
						$match_found = true;
3201
					} elseif ( $args['condition'] == 'is_greater_than' && $until_time < $now_time ) {
3202
						$match_found = true;
3203
					}
3204
				} else {
3205
					switch ( $args['condition'] ) {
3206
						case 'is_equal':
3207
							$match_found = (bool) ( $search != '' && $match_value == $search );
3208
							break;
3209
						case 'is_not_equal':
3210
							$match_found = (bool) ( $search != '' && $match_value != $search );
3211
							break;
3212
						case 'is_greater_than':
3213
							$match_found = (bool) ( $search != '' && ( is_float( $search ) || is_numeric( $search ) ) && ( is_float( $match_value ) || is_numeric( $match_value ) ) && $match_value > $search );
3214
							break;
3215
						case 'is_less_than':
3216
							$match_found = (bool) ( $search != '' && ( is_float( $search ) || is_numeric( $search ) ) && ( is_float( $match_value ) || is_numeric( $match_value ) ) && $match_value < $search );
3217
							break;
3218
						case 'is_empty':
3219
							$match_found = (bool) ( $match_value === '' || $match_value === false || $match_value === '0' || is_null( $match_value ) );
3220
							break;
3221
						case 'is_not_empty':
3222
							$match_found = (bool) ( $match_value !== '' && $match_value !== false && $match_value !== '0' && ! is_null( $match_value ) );
3223
							break;
3224
						case 'is_contains':
3225
							$match_found = (bool) ( $search != '' && stripos( $match_value, $search ) !== false );
3226
							break;
3227
						case 'is_not_contains':
3228
							$match_found = (bool) ( $search != '' && stripos( $match_value, $search ) === false );
3229
							break;
3230
					}
3231
				}
3232
			}
3233
3234
			$match_found = apply_filters( 'geodir_post_badge_check_match_found', $match_found, $args, $find_post );
3235
		}
3236
	}
3237
3238
	return $match_found;
3239
}
3240