Completed
Push — master ( 3860cc...10e837 )
by Stephanie
9s
created

FrmFieldsController::edit_option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
class FrmFieldsController {
4
5
    public static function load_field() {
6
		FrmAppHelper::permission_check('frm_edit_forms');
7
        check_ajax_referer( 'frm_ajax', 'nonce' );
8
9
        $fields = $_POST['field'];
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
10
        if ( empty( $fields ) ) {
11
            wp_die();
12
        }
13
14
        $_GET['page'] = 'formidable';
15
        $fields = stripslashes_deep( $fields );
16
17
        $ajax = true;
18
		$values = array( 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ) );
19
        $path = FrmAppHelper::plugin_path();
20
        $field_html = array();
21
22
        foreach ( $fields as $field ) {
23
            $field = htmlspecialchars_decode( nl2br( $field ) );
24
            $field = json_decode( $field, true );
25
            if ( ! isset( $field['id'] ) ) {
26
                // this field may have already been loaded
27
                continue;
28
            }
29
30
            $field_id = absint( $field['id'] );
31
32
            if ( ! isset( $field['value'] ) ) {
33
                $field['value'] = '';
34
            }
35
36
			$field_name = 'item_meta[' . $field_id . ']';
37
            $html_id = FrmFieldsHelper::get_html_id($field);
38
39
            ob_start();
40
			include( $path . '/classes/views/frm-forms/add_field.php' );
41
            $field_html[ $field_id ] = ob_get_contents();
42
            ob_end_clean();
43
        }
44
45
        unset($path);
46
47
        echo json_encode($field_html);
48
49
        wp_die();
50
    }
51
52
	/**
53
	 * Create a new field with ajax
54
	 */
55
    public static function create() {
56
		FrmAppHelper::permission_check('frm_edit_forms');
57
        check_ajax_referer( 'frm_ajax', 'nonce' );
58
59
		$field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
60
		$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
61
62
		$field = self::include_new_field( $field_type, $form_id );
0 ignored issues
show
Bug introduced by
It seems like $field_type defined by \FrmAppHelper::get_post_... 'sanitize_text_field') on line 59 can also be of type array; however, FrmFieldsController::include_new_field() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
63
64
        // this hook will allow for multiple fields to be added at once
65
        do_action('frm_after_field_created', $field, $form_id);
66
67
        wp_die();
68
    }
69
70
    /**
71
     * Set up and create a new field
72
     *
73
     * @param string $field_type
74
     * @param integer $form_id
75
     * @return array|bool
76
     */
77
	public static function include_new_field( $field_type, $form_id ) {
78
        $values = array();
79
        if ( FrmAppHelper::pro_is_installed() ) {
80
            $values['post_type'] = FrmProFormsHelper::post_type($form_id);
81
        }
82
83
		$field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
84
        $field_values = apply_filters( 'frm_before_field_created', $field_values );
85
86
        $field_id = FrmField::create( $field_values );
87
88
        if ( ! $field_id ) {
89
            return false;
90
        }
91
92
        $field = self::include_single_field($field_id, $values, $form_id);
93
94
        return $field;
95
    }
96
97
	public static function edit_name( $field = 'name', $id = '' ) {
98
		FrmAppHelper::permission_check('frm_edit_forms');
99
        check_ajax_referer( 'frm_ajax', 'nonce' );
100
101
        if ( empty($field) ) {
102
            $field = 'name';
103
        }
104
105
        if ( empty($id) ) {
106
			$id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
107
			$id = str_replace( 'field_label_', '', $id );
108
        }
109
110
		$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
111
		$value = trim( $value );
112
        if ( trim(strip_tags($value)) == '' ) {
113
            // set blank value if there is no content
114
            $value = '';
115
        }
116
117
		FrmField::update( $id, array( $field => $value ) );
118
119
		do_action( 'frm_after_update_field_' . $field, compact( 'id', 'value' ) );
120
121
		echo stripslashes( wp_kses_post( $value ) );
122
        wp_die();
123
    }
124
125
    public static function update_ajax_option() {
126
		FrmAppHelper::permission_check('frm_edit_forms');
127
        check_ajax_referer( 'frm_ajax', 'nonce' );
128
129
		$field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
130
		if ( ! $field_id ) {
131
			wp_die();
132
		}
133
134
		$field = FrmField::getOne( $field_id );
135
136
		if ( isset( $_POST['separate_value'] ) ) {
137
			$new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
138
			$field->field_options['separate_value'] = $new_val;
139
			unset($new_val);
140
		}
141
142
        FrmField::update( $field_id, array(
143
            'field_options' => $field->field_options,
144
			'form_id'		=> $field->form_id,
145
        ) );
146
        wp_die();
147
    }
148
149
    public static function duplicate() {
150
		FrmAppHelper::permission_check('frm_edit_forms');
151
        check_ajax_referer( 'frm_ajax', 'nonce' );
152
153
        global $wpdb;
154
155
		$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
156
		$form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
157
158
		$copy_field = FrmField::getOne( $field_id );
159
        if ( ! $copy_field ) {
160
            wp_die();
161
        }
162
163
		do_action( 'frm_duplicate_field', $copy_field, $form_id );
164
		do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
165
166
		$values = array();
167
        FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
168
169
		$field_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
170
171
        $values['field_order'] = $field_count + 1;
172
173
	    $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
174
175
		$field_id = FrmField::create( $values );
176
		if ( ! $field_id ) {
177
			wp_die();
178
		}
179
180
        self::include_single_field($field_id, $values);
181
182
        wp_die();
183
    }
184
185
    /**
186
     * Load a single field in the form builder along with all needed variables
187
     */
188
    public static function include_single_field( $field_id, $values, $form_id = 0 ) {
189
        $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
190
		$field_name = 'item_meta[' . $field_id . ']';
191
        $html_id = FrmFieldsHelper::get_html_id($field);
192
        $id = $form_id ? $form_id : $field['form_id'];
193
        if ( $field['type'] == 'html' ) {
194
            $field['stop_filter'] = true;
195
        }
196
197
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
198
199
        return $field;
200
    }
201
202
    public static function destroy() {
203
		FrmAppHelper::permission_check('frm_edit_forms');
204
        check_ajax_referer( 'frm_ajax', 'nonce' );
205
206
		$field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
207
		FrmField::destroy( $field_id );
208
        wp_die();
209
    }
210
211
    /* Field Options */
212
213
    //Add Single Option or Other Option
214
    public static function add_option() {
215
		FrmAppHelper::permission_check('frm_edit_forms');
216
        check_ajax_referer( 'frm_ajax', 'nonce' );
217
218
		$id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
219
		$opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
220
		$opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' );
221
222
        $field = FrmField::getOne($id);
223
224
        if ( 'other' == $opt_type ) {
225
			$opt = __( 'Other', 'formidable' );
226
            $other_val = '';
227
            $opt_key = 'other_' . $opt_key;
228
        } else {
229
			$opt = __( 'New Option', 'formidable' );
230
        }
231
        $field_val = $opt;
232
233
        $field_data = $field;
234
		$field = (array) $field;
235
		$field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0;
236
		unset( $field_data );
237
238
		$field_name = 'item_meta[' . $id . ']';
239
		$html_id = FrmFieldsHelper::get_html_id( $field );
240
        $checked = '';
241
242
        if ( 'other' == $opt_type ) {
243
			include( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' );
244
        } else {
245
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
246
        }
247
        wp_die();
248
    }
249
250
    public static function edit_option() {
251
		_deprecated_function( __FUNCTION__, '2.3' );
252
    }
253
254
    public static function delete_option() {
255
		_deprecated_function( __FUNCTION__, '2.3' );
256
    }
257
258
    public static function import_choices() {
259
        FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
260
261
		$field_id = absint( $_REQUEST['field_id'] );
0 ignored issues
show
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
262
263
        global $current_screen, $hook_suffix;
264
265
        // Catch plugins that include admin-header.php before admin.php completes.
266
        if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
267
            $hook_suffix = '';
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
268
        	set_current_screen();
269
        }
270
271
        if ( function_exists( 'register_admin_color_schemes' ) ) {
272
            register_admin_color_schemes();
273
        }
274
275
		$hook_suffix = '';
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
276
		$admin_body_class = '';
277
278
        if ( get_user_setting( 'mfold' ) == 'f' ) {
279
        	$admin_body_class .= ' folded';
280
        }
281
282
        if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
283
        	$admin_body_class .= ' admin-bar';
284
        }
285
286
        if ( is_rtl() ) {
287
        	$admin_body_class .= ' rtl';
288
        }
289
290
        $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
291
        $prepop = array();
292
        FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
293
294
        $field = FrmField::getOne($field_id);
295
296
        wp_enqueue_script( 'utils' );
297
		wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' );
298
        FrmAppHelper::load_admin_wide_js();
299
300
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' );
301
        wp_die();
302
    }
303
304
    public static function import_options() {
305
		FrmAppHelper::permission_check('frm_edit_forms');
306
        check_ajax_referer( 'frm_ajax', 'nonce' );
307
308
        if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
309
            return;
310
        }
311
312
		$field_id = absint( $_POST['field_id'] );
0 ignored issues
show
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
313
        $field = FrmField::getOne($field_id);
314
315
		if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
316
            return;
317
        }
318
319
        $field = FrmFieldsHelper::setup_edit_vars($field);
320
		$opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
321
		$opts = explode( "\n", rtrim( $opts, "\n" ) );
322
		$opts = array_map( 'trim', $opts );
323
324
        if ( $field['separate_value'] ) {
325
            foreach ( $opts as $opt_key => $opt ) {
326
                if ( strpos($opt, '|') !== false ) {
327
                    $vals = explode('|', $opt);
328
                    if ( $vals[0] != $vals[1] ) {
329
                        $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
330
                    }
331
                    unset($vals);
332
                }
333
                unset($opt_key, $opt);
334
            }
335
        }
336
337
        //Keep other options after bulk update
338
        if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
339
            $other_array = array();
340
            foreach ( $field['options'] as $opt_key => $opt ) {
341
                if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
342
                    $other_array[ $opt_key ] = $opt;
343
                }
344
                unset($opt_key, $opt);
345
            }
346
            if ( ! empty($other_array) ) {
347
                $opts = array_merge( $opts, $other_array);
348
            }
349
        }
350
351
        $field['options'] = $opts;
352
353
        if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
354
			$field_name = 'item_meta[' . $field['id'] . ']';
355
356
			// Get html_id which will be used in single-option.php
357
			$html_id = FrmFieldsHelper::get_html_id( $field );
358
359
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' );
360
        } else {
361
            FrmFieldsHelper::show_single_option($field);
362
        }
363
364
        wp_die();
365
    }
366
367
    public static function update_order() {
368
		FrmAppHelper::permission_check('frm_edit_forms');
369
        check_ajax_referer( 'frm_ajax', 'nonce' );
370
371
		$fields = FrmAppHelper::get_post_param( 'frm_field_id' );
372
		foreach ( (array) $fields as $position => $item ) {
373
			FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) );
374
		}
375
        wp_die();
376
    }
377
378
	public static function change_type( $type ) {
379
        $type_switch = array(
380
            'scale'     => 'radio',
381
            '10radio'   => 'radio',
382
            'rte'       => 'textarea',
383
            'website'   => 'url',
384
        );
385
        if ( isset( $type_switch[ $type ] ) ) {
386
            $type = $type_switch[ $type ];
387
        }
388
389
		$pro_fields = FrmField::pro_field_selection();
390
		$types = array_keys( $pro_fields );
391
		if ( in_array( $type, $types ) ) {
392
			$type = 'text';
393
		}
394
395
        return $type;
396
    }
397
398
	public static function display_field_options( $display ) {
399
		switch ( $display['type'] ) {
400
            case 'captcha':
401
                $display['required'] = false;
402
                $display['invalid'] = true;
403
                $display['default_blank'] = false;
404
				$display['captcha_size'] = true;
405
            break;
406
            case 'radio':
407
                $display['default_blank'] = false;
408
            break;
409
            case 'text':
410
            case 'textarea':
411
                $display['size'] = true;
412
                $display['clear_on_focus'] = true;
413
            break;
414
            case 'select':
415
                $display['size'] = true;
416
            break;
417
            case 'url':
418
            case 'website':
419
            case 'email':
420
                $display['size'] = true;
421
                $display['clear_on_focus'] = true;
422
                $display['invalid'] = true;
423
        }
424
425
        return $display;
426
    }
427
428
    public static function input_html( $field, $echo = true ) {
429
        $class = array(); //$field['type'];
430
        self::add_input_classes($field, $class);
431
432
        $add_html = array();
433
        self::add_html_size($field, $add_html);
434
        self::add_html_length($field, $add_html);
435
        self::add_html_placeholder($field, $add_html, $class);
436
		self::add_validation_messages( $field, $add_html );
437
438
        $class = apply_filters('frm_field_classes', implode(' ', $class), $field);
439
440
		FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
441
442
        self::add_shortcodes_to_html($field, $add_html);
443
444
		$add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
445
		$add_html = ' ' . implode( ' ', $add_html ) . '  ';
446
447
        if ( $echo ) {
448
            echo $add_html;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$add_html'
Loading history...
449
        }
450
451
        return $add_html;
452
    }
453
454
	private static function add_input_classes( $field, array &$class ) {
455
        if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
456
            $class[] = $field['input_class'];
457
        }
458
459
        if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
460
            return;
461
        }
462
463
        if ( isset($field['size']) && $field['size'] > 0 ) {
464
            $class[] = 'auto_width';
465
        }
466
    }
467
468
	private static function add_html_size( $field, array &$add_html ) {
469
		if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) {
470
            return;
471
        }
472
473
        if ( FrmAppHelper::is_admin_page('formidable' ) ) {
474
            return;
475
        }
476
477
        if ( is_numeric($field['size']) ) {
478
            $field['size'] .= 'px';
479
        }
480
481
        $important = apply_filters('frm_use_important_width', 1, $field);
482
        // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
483
		$add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
484
485
        self::add_html_cols($field, $add_html);
486
    }
487
488
	private static function add_html_cols( $field, array &$add_html ) {
489
		if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
490
            return;
491
        }
492
493
        // convert to cols for textareas
494
        $calc = array(
495
            ''      => 9,
496
            'px'    => 9,
497
            'rem'   => 0.444,
498
            'em'    => 0.544,
499
        );
500
501
        // include "col" for valid html
502
        $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
503
504
        if ( ! isset( $calc[ $unit ] ) ) {
505
            return;
506
        }
507
508
        $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
509
510
		$add_html['cols'] = 'cols="' . absint( $size ) . '"';
511
    }
512
513
	private static function add_html_length( $field, array &$add_html ) {
514
        // check for max setting and if this field accepts maxlength
515
		if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) {
516
            return;
517
        }
518
519
        if ( FrmAppHelper::is_admin_page('formidable' ) ) {
520
            // don't load on form builder page
521
            return;
522
        }
523
524
		$add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
525
    }
526
527
	private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
528
		if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) {
529
			return;
530
		}
531
532
		$default_value_array = is_array( $field['default_value'] );
533
        if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
534
			if ( $default_value_array ) {
535
				$field['default_value'] = json_encode( $field['default_value'] );
536
			}
537
			$add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
538
            return;
539
        }
540
541
		if ( $default_value_array ) {
542
			// don't include a json placeholder
543
			return;
544
		}
545
546
        $frm_settings = FrmAppHelper::get_settings();
547
548
		if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) {
549
            // use HMTL5 placeholder with js fallback
550
			$add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
551
            wp_enqueue_script('jquery-placeholder');
552
        } else if ( ! $frm_settings->use_html ) {
553
			$val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( '&#039;', "'", esc_attr( $field['default_value'] ) ) ) );
554
			$add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"';
555
            $class[] = 'frm_toggle_default';
556
557
            if ( $field['value'] == $field['default_value'] ) {
558
                $class[] = 'frm_default';
559
            }
560
        }
561
    }
562
563
	private static function add_validation_messages( $field, array &$add_html ) {
564 View Code Duplication
		if ( FrmField::is_required( $field ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
565
			$required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
566
			$add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
567
		}
568
569 View Code Duplication
		if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
570
			$invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
571
			$add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
572
		}
573
	}
574
575
    private static function add_shortcodes_to_html( $field, array &$add_html ) {
576
        if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
577
            return;
578
        }
579
580
        foreach ( $field['shortcodes'] as $k => $v ) {
581
            if ( 'opt' === $k ) {
582
                continue;
583
            }
584
585
            if ( is_numeric($k) && strpos($v, '=') ) {
586
                $add_html[] = $v;
587
            } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
588
				$add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
589
            } else {
590
				$add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
591
            }
592
593
            unset($k, $v);
594
        }
595
    }
596
597
    public static function check_value( $opt, $opt_key, $field ) {
598
        if ( is_array( $opt ) ) {
599
            if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
600
                $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
601
            } else {
602
                $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
603
            }
604
        }
605
        return $opt;
606
    }
607
608
	public static function check_label( $opt ) {
609 View Code Duplication
        if ( is_array($opt) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
610
            $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
611
        }
612
613
        return $opt;
614
    }
615
}
616