Completed
Push — issues/1038 ( f8946f...67d5d4 )
by Ravinder
16:51
created

Give_Fields_API::render_field_wrapper()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 4
nop 1
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Fields API
5
 *
6
 * @package     Give
7
 * @subpackage  Classes/Give_Fields_API
8
 * @copyright   Copyright (c) 2016, WordImpress
9
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
10
 * @since       1.9
11
 */
12
class Give_Fields_API {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
13
	/**
14
	 * Instance.
15
	 *
16
	 * @since  1.9
17
	 * @access private
18
	 * @var Give_Fields_API
19
	 */
20
	static private $instance;
21
22
	/**
23
	 * The defaults for all elements
24
	 *
25
	 * @since  1.9
26
	 * @access static
27
	 */
28
	static $field_defaults = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $field_defaults.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
29
		'type'                 => '',
30
		'name'                 => '',
31
		'data_type'            => '',
32
		'value'                => '',
33
		'required'             => false,
34
		'options'              => array(),
35
36
		// Set default value to field.
37
		'default'              => '',
38
39
		// Add label, before and after field.
40
		'label'                => '',
41
		'label_position'       => 'before',
42
43
		// Add description to field as tooltip.
44
		'tooltip'              => '',
45
46
		// Show multiple fields in same row with in sub section.
47
		'sub_section_start'    => false,
48
		'sub_section_end'      => false,
49
50
		// Add custom attributes.
51
		'field_attributes'     => array(),
52
		'wrapper_attributes'   => array(),
53
54
		// Show/Hide field in before/after modal view.
55
		'show_without_modal'   => false,
56
		'show_within_modal'    => true,
57
58
		// Params to edit field html.
59
		'before_field'         => '',
60
		'after_field'          => '',
61
		'before_field_wrapper' => '',
62
		'after_field_wrapper'  => '',
63
		'before_label'         => '',
64
		'after_label'          => '',
65
66
		// Manually render field.
67
		'callback'             => '',
68
69
	);
70
71
	/**
72
	 * The defaults for all sections.
73
	 *
74
	 * @since  1.9
75
	 * @access static
76
	 */
77
	static $section_defaults = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $section_defaults.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
78
		'label'              => '',
79
		'name'               => '',
80
		'section_attributes' => array(),
81
82
		// Manually render section.
83
		'callback'           => '',
84
	);
85
86
	/**
87
	 * The defaults for all blocks.
88
	 *
89
	 * @since  1.9
90
	 * @access static
91
	 */
92
	static $block_defaults = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $block_defaults.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
93
		'label'            => '',
94
		'name'             => '',
95
		'block_attributes' => array(),
96
97
		// Manually render section.
98
		'callback'         => '',
99
	);
100
101
102
	private function __construct() {
103
	}
104
105
106
	/**
107
	 * Get instance.
108
	 *
109
	 * @return static
110
	 */
111
	public static function get_instance() {
112
		if ( is_null( static::$instance ) ) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
113
			self::$instance = new static();
114
		}
115
116
		return self::$instance;
117
	}
118
119
	/**
120
	 * Initialize this module
121
	 *
122
	 * @since  1.9
123
	 * @access static
124
	 */
125
	public function init() {
126
		add_filter( 'give_form_api_render_form_tags', array( $this, 'render_tags' ), 10, 2 );
127
	}
128
129
130
	/**
131
	 * Render custom field.
132
	 *
133
	 * @since  1.0
134
	 * @access private
135
	 *
136
	 * @param array $field
137
	 *
138
	 * @return bool
139
	 */
140
	private function render_custom_field( $field ) {
141
		$field_html = '';
142
143
		if ( empty( $field['callback'] ) ) {
144
			$callback = $field['callback'];
145
146
			// Process callback to get field html.
147
			if ( is_string( $callback ) && function_exists( "$callback" ) ) {
148
				$field_html = $callback( $field );
149
			} elseif ( is_array( $callback ) && method_exists( $callback[0], "$callback[1]" ) ) {
150
				$field_html = $callback[0]->$callback[1]( $field );
151
			}
152
		}
153
154
		return $field_html;
155
	}
156
157
158
	/**
159
	 * Render `{{form_fields}}` tag.
160
	 *
161
	 * @since  1.9
162
	 * @access private
163
	 *
164
	 * @param  string $form_html
165
	 * @param  array  $form
166
	 *
167
	 * @return string
168
	 */
169
	public function render_tags( $form_html, $form ) {
170
		// Bailout: If form does not contain any field.
171
		if ( empty( $form['fields'] ) ) {
172
			str_replace( '{{form_fields}}', '', $form_html );
173
174
			return $form_html;
175
		}
176
177
		$fields_html = '';
178
179
		// Set responsive fields.
180
		self::$instance->set_responsive_field( $form );
181
182
		// Render fields.
183
		foreach ( $form['fields'] as $key => $field ) {
184
			// Set default value.
185
			$field['name'] = empty( $field['name'] ) ? $key : $field['name'];
186
			$field         = self::$instance->set_default_values( $field, $form );
187
188
189
			// Render custom form with callback.
190
			if ( $field_html = self::$instance->render_custom_field( $field ) ) {
191
				$fields_html .= $field_html;
192
			}
193
194
			switch ( true ) {
195
				// Block.
196
				case ( array_key_exists( 'type', $field ) && 'block' === $field['type'] ):
197
					$fields_html .= self::$instance->render_block( $field, $form );
198
					break;
199
200
				// Section.
201
				case array_key_exists( 'fields', $field ):
202
					$fields_html .= self::$instance->render_section( $field, $form );
203
					break;
204
205
				// Field
206
				default:
207
					$fields_html .= self::render_tag( $field, $form );
208
			}
209
		}
210
211
		$form_html = str_replace( '{{form_fields}}', $fields_html, $form_html );
212
213
		return $form_html;
214
	}
215
216
217
	/**
218
	 * Render section.
219
	 *
220
	 * @since  1.9
221
	 * @access public
222
	 *
223
	 * @param array $section
224
	 * @param array $form
225
	 *
226
	 * @return string
227
	 */
228
	public static function render_section( $section, $form = null ) {
229
		ob_start();
230
		?>
231
		<fieldset <?php echo self::$instance->get_attributes( $section['section_attributes'] ); ?>>
232
			<?php
233
			// Legend.
234
			if ( ! empty( $section['label'] ) ) {
235
				echo "<legend>{$section['label']}</legend>";
236
			};
237
238
			// Fields.
239
			foreach ( $section['fields'] as $key => $field ) {
240
				echo self::render_tag( $field, $form );
241
			}
242
			?>
243
		</fieldset>
244
		<?php
245
		return ob_get_clean();
246
	}
247
248
249
	/**
250
	 * Render block.
251
	 *
252
	 * @since  1.9
253
	 * @access public
254
	 *
255
	 * @param array $section
256
	 * @param array $form
257
	 *
258
	 * @return string
259
	 */
260
	public static function render_block( $section, $form = null ) {
261
		ob_start();
262
		?>
263
		<div <?php echo self::$instance->get_attributes( $section['block_attributes'] ); ?>>
264
			<?php
265
			// Fields.
266
			foreach ( $section['fields'] as $key => $field ) {
267
				echo array_key_exists( 'fields', $field )
268
					? self::render_section( $field, $form )
269
					: self::render_tag( $field, $form );
270
			}
271
			?>
272
		</div>
273
		<?php
274
		return ob_get_clean();
275
	}
276
277
	/**
278
	 * Render tag
279
	 *
280
	 * @since   1.9
281
	 * @access  public
282
	 *
283
	 * @param $field
284
	 * @param $form
285
	 *
286
	 * @return string
287
	 */
288
	public static function render_tag( $field, $form = null ) {
289
		$field_html     = '';
290
		$functions_name = "render_{$field['type']}_field";
291
292
		if ( method_exists( self::$instance, $functions_name ) ) {
293
			$field_html .= self::$instance->{$functions_name}( $field );
294
		} else {
295
			$field_html .= apply_filters( "give_field_api_render_{$field['type']}_field", '', $field, $form );
296
		}
297
298
		return $field_html;
299
	}
300
301
302
	/**
303
	 * Render text field.
304
	 *
305
	 * @since  1.9
306
	 * @access private
307
	 *
308
	 * @param  array $field
309
	 *
310
	 * @return string
311
	 */
312
	public static function render_text_field( $field ) {
313
		$field_wrapper = self::$instance->render_field_wrapper( $field );
314
		ob_start();
315
		?>
316
		<input
317
				type="<?php echo $field['type']; ?>"
318
				name="<?php echo $field['name']; ?>"
319
				value="<?php echo $field ['value']; ?>"
320
			<?php echo( $field['required'] ? 'required=""' : '' ); ?>
321
			<?php echo self::$instance->get_attributes( $field['field_attributes'] ); ?>
322
		>
323
		<?php
324
325
		return str_replace( '{{form_field}}', ob_get_clean(), $field_wrapper );
326
	}
327
328
	/**
329
	 * Render submit field.
330
	 *
331
	 * @since  1.9
332
	 * @access private
333
	 *
334
	 * @param  array $field
335
	 *
336
	 * @return string
337
	 */
338
	public static function render_submit_field( $field ) {
339
		return self::$instance->render_text_field( $field );
340
	}
341
342
	/**
343
	 * Render checkbox field.
344
	 *
345
	 * @since  1.9
346
	 * @access private
347
	 *
348
	 * @param  array $field
349
	 *
350
	 * @return string
351
	 */
352
	public static function render_checkbox_field( $field ) {
353
		return self::$instance->render_text_field( $field );
354
	}
355
356
	/**
357
	 * Render email field.
358
	 *
359
	 * @since  1.9
360
	 * @access private
361
	 *
362
	 * @param  array $field
363
	 *
364
	 * @return string
365
	 */
366
	public static function render_email_field( $field ) {
367
		return self::$instance->render_text_field( $field );
368
	}
369
370
	/**
371
	 * Render number field.
372
	 *
373
	 * @since  1.9
374
	 * @access private
375
	 *
376
	 * @param  array $field
377
	 *
378
	 * @return string
379
	 */
380
	public static function render_number_field( $field ) {
381
		return self::$instance->render_text_field( $field );
382
	}
383
384
	/**
385
	 * Render password field.
386
	 *
387
	 * @since  1.9
388
	 * @access private
389
	 *
390
	 * @param  array $field
391
	 *
392
	 * @return string
393
	 */
394
	public static function render_password_field( $field ) {
395
		return self::$instance->render_text_field( $field );
396
	}
397
398
	/**
399
	 * Render textarea field.
400
	 *
401
	 * @since  1.9
402
	 * @access private
403
	 *
404
	 * @param  array $field
405
	 *
406
	 * @return string
407
	 */
408
	public static function render_textarea_field( $field ) {
409
		$field_wrapper = self::$instance->render_field_wrapper( $field );
410
		ob_start();
411
		?>
412
		<textarea
413
				name="<?php echo $field['name']; ?>"
414
			<?php echo( $field['required'] ? 'required=""' : '' ); ?>
415
			<?php echo self::$instance->get_attributes( $field['field_attributes'] ); ?>
416
		><?php echo $field ['value']; ?></textarea>
417
418
419
		<?php
420
421
		return str_replace( '{{form_field}}', ob_get_clean(), $field_wrapper );
422
	}
423
424
	/**
425
	 * Render select field.
426
	 *
427
	 * @since  1.9
428
	 * @access private
429
	 *
430
	 * @param  array $field
431
	 *
432
	 * @return string
433
	 */
434
	public static function render_select_field( $field ) {
435
		$field_wrapper = self::$instance->render_field_wrapper( $field );
436
		ob_start();
437
438
		$options_html = '';
439
		foreach ( $field['options'] as $key => $option ) {
440
			$options_html .= "<option value=\"{$key}\">{$option}</option>";
441
		}
442
		?>
443
444
		<select
445
				name="<?php echo $field['name']; ?>"
446
			<?php echo( $field['required'] ? 'required=""' : '' ); ?>
447
			<?php echo self::$instance->get_attributes( $field['field_attributes'] ); ?>
448
		><?php echo $options_html; ?></select>
449
		<?php
450
451
		return str_replace( '{{form_field}}', ob_get_clean(), $field_wrapper );
452
	}
453
454
	/**
455
	 * Render multi select field.
456
	 *
457
	 * @since  1.9
458
	 * @access private
459
	 *
460
	 * @param  array $field
461
	 *
462
	 * @return string
463
	 */
464
	public static function render_multi_select_field( $field ) {
465
		$field['field_attributes'] = array_merge( $field['field_attributes'], array( 'multiple' => 'multiple' ) );
466
		$field['name']             = "{$field['name']}[]";
467
468
		return self::$instance->render_select_field( $field );
469
	}
470
471
	/**
472
	 * Render text field.
473
	 *
474
	 * @since  1.9
475
	 * @access private
476
	 *
477
	 * @param  array $field
478
	 *
479
	 * @return string
480
	 */
481
	public static function render_radio_field( $field ) {
482
		$field_wrapper = self::$instance->render_field_wrapper( $field );
483
		ob_start();
484
		foreach ( $field['options'] as $key => $option ) :
485
			// @todo id issue.
486
			?>
487
			<input
488
			type="<?php echo $field['type']; ?>"
489
			name="<?php echo $field['name']; ?>"
490
			value="<?php echo $key; ?>"
491
			<?php echo( $field['required'] ? 'required=""' : '' ); ?>
492
			<?php echo self::$instance->get_attributes( $field['field_attributes'] ); ?>
493
			><?php echo $option; ?>
494
			<?php
495
		endforeach;
496
497
		return str_replace( '{{form_field}}', ob_get_clean(), $field_wrapper );
498
	}
499
500
501
	/**
502
	 * Render wrapper
503
	 *
504
	 * @since  1.9
505
	 * @access private
506
	 *
507
	 * @param $field
508
	 *
509
	 * @return string
510
	 */
511
	private function render_field_wrapper( $field ) {
512
		ob_start();
513
514
		echo $field['before_field_wrapper'];
515
		?>
516
		<p <?php echo self::$instance->get_attributes( $field['wrapper_attributes'] ); ?>>
517
			<?php
518
			// Label: before field.
519
			if ( 'before' === $field['label_position'] ) {
520
				echo self::$instance->render_label( $field );
521
			}
522
523
			echo $field['before_field'];
524
			?>
525
526
			{{form_field}}
527
528
			<?php
529
			echo $field['before_field'];
530
531
			// Label: before field.
532
			if ( 'after' === $field['label_position'] ) {
533
				echo self::$instance->render_label( $field );
534
			}
535
			?>
536
		</p>
537
		<?php
538
		echo $field['after_field_wrapper'];
539
540
		return ob_get_clean();
541
	}
542
543
544
	/**
545
	 * Render label
546
	 *
547
	 * @since  1.9
548
	 * @access private
549
	 *
550
	 * @param $field
551
	 *
552
	 * @return string
553
	 */
554
	private function render_label( $field ) {
555
		ob_start();
556
		?>
557
		<?php if ( ! empty( $field['label'] ) ) : ?>
558
			<?php echo $field['before_label']; ?>
559
			<label class="give-label" for="<?php echo $field['field_attributes']['id']; ?>">
560
561
				<?php echo $field['label']; ?>
562
563
				<?php if ( $field['required'] ) : ?>
564
					<span class="give-required-indicator">*</span>
565
				<?php endif; ?>
566
567
				<?php if ( $field['tooltip'] ) : ?>
568
					<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php echo $field['tooltip'] ?>"></span>
569
				<?php endif; ?>
570
			</label>
571
			<?php echo $field['after_label']; ?>
572
		<?php endif; ?>
573
		<?php
574
		return ob_get_clean();
575
	}
576
577
	/**
578
	 * Get field attribute string from field arguments.
579
	 *
580
	 * @since  1.9
581
	 * @access private
582
	 *
583
	 * @param array $attributes
584
	 *
585
	 * @return array|string
586
	 */
587
	private function get_attributes( $attributes ) {
588
		$field_attributes_val = '';
589
590
		if ( ! empty( $attributes ) ) {
591
			foreach ( $attributes as $attribute_name => $attribute_val ) {
592
				$field_attributes_val[] = "{$attribute_name}=\"{$attribute_val}\"";
593
			}
594
		}
595
596
		if ( ! empty( $field_attributes_val ) ) {
597
			$field_attributes_val = implode( ' ', $field_attributes_val );
598
		}
599
600
		return $field_attributes_val;
601
	}
602
603
	/**
604
	 * Set default values for fields
605
	 *
606
	 * @since  1.0
607
	 * @access private
608
	 *
609
	 * @param array $field
610
	 * @param array $form
611
	 * @param bool  $fire_filter
612
	 *
613
	 * @return array
614
	 */
615
	private function set_default_values( $field, $form = null, $fire_filter = true ) {
616
617
		switch ( self::$instance->get_field_type( $field ) ) {
618
			case 'block':
619
				// Set default values for block.
620
				$field = wp_parse_args( $field, self::$block_defaults );
621
622
				foreach ( $field['fields'] as $key => $single_field ) {
623
					$single_field['name']    = ! empty( $single_field['name'] )
624
						? $single_field['name']
625
						: $key;
626
					$field['fields'][ $key ] = self::$instance->set_default_values( $single_field, $form, false );
627
				}
628
629
				break;
630
631
			case 'section':
632
				// Set default values for block.
633
				$field = wp_parse_args( $field, self::$section_defaults );
634
635
				foreach ( $field['fields'] as $key => $single_field ) {
636
					$single_field['name']    = ! empty( $single_field['name'] )
637
						? $single_field['name']
638
						: $key;
639
					$field['fields'][ $key ] = self::$instance->set_default_values( $single_field, $form, false );
640
				}
641
642
				break;
643
644
			default:
645
				// Set default values for field or section.
646
				$field = wp_parse_args( $field, self::$field_defaults );
647
648
				// Default field classes.
649
				$default_class = "give-field give-field-js give-field-type-{$field['type']}";
650
651
				// Set ID.
652
				$field['field_attributes']['id'] = empty( $field['field_attributes']['id'] )
653
					? "give-{$field['name']}-field"
654
					: $field['field_attributes']['id'];
655
656
				// Set class.
657
				$field['field_attributes']['class'] = empty( $field['field_attributes']['class'] )
658
					? $default_class
659
					: "{$default_class} {$field['field_attributes']['class']}";
660
661
				// Set wrapper class.
662
				$field['wrapper_attributes']['class'] = empty( $field['wrapper_attributes']['class'] )
663
					? 'give-field-row'
664
					: "give-field-row {$field['wrapper_attributes']['class']}";
665
		}
666
667
		/**
668
		 * Filter the field.
669
		 *
670
		 * @since 1.9
671
		 *
672
		 * @param array $field
673
		 * @param array $form
674
		 */
675
		$field = $fire_filter
676
			? apply_filters( 'give_field_api_set_default_values', $field, $form )
677
			: $field;
678
679
		return $field;
680
	}
681
682
683
	/**
684
	 * Set responsive fields.
685
	 *
686
	 * @since  1.9
687
	 * @access private
688
	 *
689
	 * @param $form
690
	 *
691
	 * @return mixed
692
	 */
693
	private function set_responsive_field( &$form ) {
694
695
		foreach ( $form['fields'] as $key => $field ) {
696
			switch ( true ) {
697
				case array_key_exists( 'fields', $field ):
698
					foreach ( $field['fields'] as $section_field_index => $section_field ) {
699
						if ( ! self::$instance->is_sub_section( $section_field ) ) {
700
							continue;
701
						}
702
703
						$form['fields'][ $key ]['fields'][ $section_field_index ]['wrapper_attributes']['class'] = 'give-form-col';
704
705
						if ( array_key_exists( 'sub_section_end', $section_field ) ) {
706
							$form['fields'][ $key ]['fields'][ $section_field_index ]['wrapper_attributes']['class'] = 'give-form-col give-form-col-end';
707
708
							// Clear float left for next field.
709
							$fields_keys = array_keys( $form['fields'][ $key ]['fields'] );
710
711
							if ( $next_field_key = array_search( $section_field_index, $fields_keys ) ) {
712
								if (
713
									! isset( $fields_keys[ $next_field_key + 1 ] )
714
									|| ! isset( $form['fields'][ $key ]['fields'][ $fields_keys[ $next_field_key + 1 ] ] )
715
								) {
716
									continue;
717
								}
718
719
								$next_field = $form['fields'][ $key ]['fields'][ $fields_keys[ $next_field_key + 1 ] ];
720
721
								$next_field['wrapper_attributes']['class'] = isset( $next_field['wrapper_attributes']['class'] )
722
									? $next_field['wrapper_attributes']['class'] . ' give-clearfix'
723
									: 'give-clearfix';
724
725
								$form['fields'][ $key ]['fields'][ $fields_keys[ $next_field_key + 1 ] ] = $next_field;
726
							}
727
						}
728
					}
729
730
					break;
731
732
				default:
733
					if ( ! self::$instance->is_sub_section( $field ) ) {
734
						continue;
735
					}
736
737
					$form['fields'][ $key ]['wrapper_attributes']['class'] = 'give-form-col';
738
739
					if ( array_key_exists( 'sub_section_end', $field ) ) {
740
						$form['fields'][ $key ]['wrapper_attributes']['class'] = 'give-form-col give-form-col-end';
741
742
						// Clear float left for next field.
743
						$fields_keys = array_keys( $form['fields'] );
744
745
						if ( $next_field_key = array_search( $key, $fields_keys ) ) {
746
							$form['fields'][ $fields_keys[ $next_field_key + 1 ] ]['wrapper_attributes']['class'] = 'give-clearfix';
747
						}
748
					}
749
			}
750
		}
751
	}
752
753
754
	/**
755
	 * Check if current field is part of sub section or not.
756
	 *
757
	 * @since  1.9
758
	 * @access private
759
	 *
760
	 * @param $field
761
	 *
762
	 * @return bool
763
	 */
764
	private function is_sub_section( $field ) {
765
		$is_sub_section = false;
766
		if ( array_key_exists( 'sub_section_start', $field ) || array_key_exists( 'sub_section_end', $field ) ) {
767
			$is_sub_section = true;
768
		}
769
770
		return $is_sub_section;
771
	}
772
773
774
	/**
775
	 * Get field type.
776
	 *
777
	 * @since  1.9
778
	 * @access private
779
	 *
780
	 * @param $field
781
	 *
782
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
783
	 */
784
	private function get_field_type( $field ) {
785
		$field_type = 'field';
786
787
		if (
788
			isset( $field['type'] )
789
			&& 'block' === $field['type']
790
		) {
791
			$field_type = 'block';
792
793
		} else if ( array_key_exists( 'fields', $field ) ) {
794
			$field_type = 'section';
795
796
		}
797
798
		return $field_type;
799
	}
800
801
	/**
802
	 * Is the element a button?
803
	 *
804
	 * @since  1.9
805
	 * @access static
806
	 *
807
	 * @param array $element
808
	 *
809
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
810
	 */
811
	static function is_button( $element ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
812
		return preg_match( '/^button|submit$/', $element['#type'] );
813
	}
814
}
815
// @todo auto fill field values.
816
// @todo set clearfix class for section also