PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormMigrator.php +82 -430 6.26 → 3.06.06 View file →
@@ -1,57 +1,18 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 abstract class FrmFormMigrator {
7 4
8 - /**
9 - * @var bool
10 - */
11 5 public $source_active;
12 6
13 - /**
14 - * @var string
15 - */
16 7 public $slug;
17 -
18 - /**
19 - * @var string
20 - */
21 8 public $path;
22 -
23 - /**
24 - * @var string
25 - */
26 9 public $name;
27 10
28 - /**
29 - * @var array
30 - */
31 11 public $response = array();
32 -
33 - /**
34 - * @var string
35 - */
36 12 public $tracking = 'frm_forms_imported';
37 13
38 14 /**
39 - * @var array
40 - */
41 - protected $fields_map = array();
42 -
43 - /**
44 - * @var mixed
45 - */
46 - protected $current_source_form;
47 -
48 - /**
49 - * @var array
50 - */
51 - protected $current_section = array();
52 -
53 - /**
54 15 * Define required properties.
55 16 */
56 17 public function __construct() {
57 18 if ( ! is_admin() ) {
@@ -57,14 +18,9 @@
57 18 if ( ! is_admin() ) {
58 19 return;
59 20 }
60 21
61 - if ( ! function_exists( 'is_plugin_active' ) ) {
62 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
63 - }
64 -
65 22 $this->source_active = is_plugin_active( $this->path );
66 -
67 23 if ( ! $this->source_active ) {
68 24 // if source plugin is not installed, do nothing
69 25 return;
70 26 }
@@ -76,89 +32,55 @@
76 32 'unsupported' => array(),
77 33 );
78 34 }
79 35
80 - /**
81 - * @return void
82 - */
83 36 private function maybe_add_to_import_page() {
84 - add_action( 'frm_import_settings', array( $this, 'import_page' ) );
37 + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
38 + add_action( $menu_name . '_page_formidable-import', array( $this, 'import_page' ), 1 );
85 39 add_action( 'wp_ajax_frm_import_' . $this->slug, array( $this, 'import_forms' ) );
86 40 }
87 41
88 - /**
89 - * @return void
90 - */
91 42 public function import_page() {
92 - $forms = $this->get_forms();
93 43 ?>
94 44 <div class="wrap">
95 - <h2 class="frm-h2"><?php echo esc_html( $this->name ); ?> Importer</h2>
96 - <p class="howto">Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>.</p>
97 - <div id="welcome-panel">
98 - <div style="margin-bottom:10px;">
45 + <div class="welcome-panel" id="welcome-panel">
46 + <h2><?php echo esc_html( $this->name ); ?> Importer</h2>
47 + <div class="welcome-panel-content" style="text-align:center;margin-bottom:10px;">
99 48 <p class="about-description">
49 + Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>. <br/>
100 50 Select the forms to import.
101 51 </p>
102 - <form class="frm_form_importer" method="post"
103 - action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
52 + <form id="frm_form_importer" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
104 53 <?php wp_nonce_field( 'nonce', 'frm_ajax' ); ?>
105 54 <input type="hidden" name="slug" value="<?php echo esc_attr( $this->slug ); ?>" />
106 55 <input type="hidden" name="action" value="frm_import_<?php echo esc_attr( $this->slug ); ?>" />
107 - <div style="max-width:400px;text-align:left;">
108 - <?php
109 - if ( ! $forms ) {
110 - esc_html_e( 'No Forms Found.', 'formidable' );
111 - }
112 - ?>
113 - <?php foreach ( $forms as $form_id => $name ) { ?>
56 + <div style="margin:10px auto;max-width:400px;text-align:left;">
57 + <?php foreach ( $this->get_forms() as $form_id => $name ) { ?>
114 58 <p>
115 59 <label>
116 - <input type="checkbox" name="form_id[]"
117 - value="<?php echo esc_attr( $form_id ); ?>" checked="checked" />
60 + <input type="checkbox" name="form_id[]" value="<?php echo esc_attr( $form_id ); ?>" checked="checked" />
118 61 <?php
119 62 echo esc_html( $name );
120 63 $new_form_id = $this->is_imported( $form_id );
121 64 ?>
122 65 <?php if ( $new_form_id ) { ?>
123 - (<a href="<?php echo esc_url( FrmForm::get_edit_link( $new_form_id ) ); ?>">previously imported</a>)
66 + (<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $new_form_id ) ); ?>">previously imported</a>)
124 67 <?php } ?>
125 68 </label>
126 69 </p>
127 70 <?php } ?>
128 71 </div>
129 - <?php
130 - $button_atts = array(
131 - 'type' => 'submit',
132 - 'class' => 'button button-primary frm-button-primary',
133 - );
134 -
135 - if ( ! $forms ) {
136 - $button_atts['disabled'] = 'disabled';
137 - }
138 - ?>
139 - <p class="submit">
140 - <button <?php FrmAppHelper::array_to_html_params( $button_atts, true ); ?>>
141 - <?php esc_html_e( 'Start Import', 'formidable' ); ?>
142 - </button>
143 - </p>
72 + <button type="submit" class="button button-primary button-hero">Start Import</button>
144 73 </form>
145 - <div id="frm-importer-process" class="frm-importer-process frm_hidden">
74 + <div id="frm-importer-process" class="frm_hidden">
146 75
147 76 <p class="process-count">
148 - <span class="frm-wait" aria-hidden="true"></span>
149 - Importing <span class="form-current">1</span> of <span class="form-total">0</span> forms
150 - from <?php echo esc_html( $this->name ); ?>.
77 + <i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
78 + Importing <span class="form-current">1</span> of <span class="form-total">0</span> forms from <?php echo esc_html( $this->name ); ?>.
151 79 </p>
152 80
153 81 <p class="process-completed" class="frm_hidden">
154 - <?php
155 - printf(
156 - // translators: %s is the number of forms that were imported.
157 - esc_html__( 'The import process has finished! We have successfully imported %s forms. You can review the results below.', 'formidable' ),
158 - '<span class="forms-completed"></span>'
159 - );
160 - ?>
82 + The import process has finished! We have successfully imported <span class="forms-completed"></span> forms. You can review the results below.
161 83 </p>
162 84
163 85 <div class="status"></div>
164 86
@@ -170,10 +92,8 @@
170 92 }
171 93
172 94 /**
173 95 * Import all forms using ajax
174 - *
175 - * @return void
176 96 */
177 97 public function import_forms() {
178 98
179 99 check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -188,10 +108,9 @@
188 108 );
189 109
190 110 if ( is_array( $forms ) ) {
191 111 $imported = array();
192 -
193 - foreach ( $forms as $form_id ) {
112 + foreach ( (array) $forms as $form_id ) {
194 113 $imported[] = $this->import_form( $form_id );
195 114 }
196 115 } else {
197 116 $imported = $this->import_form( $forms );
@@ -201,22 +120,15 @@
201 120 }
202 121
203 122 /**
204 123 * Import a single form
205 - *
206 - * @param int $source_id Source form ID.
207 - *
208 - * @return array
209 124 */
210 125 protected function import_form( $source_id ) {
211 126
212 - $source_form = $this->get_form( $source_id );
213 - $source_form_name = $this->get_form_name( $source_form );
214 - $source_fields = $this->get_form_fields( $source_form );
215 - $this->maybe_add_end_fields( $source_fields );
127 + $source_form = $this->get_form( $source_id );
128 + $source_form_name = $this->get_form_name( $source_form );
129 + $source_fields = $this->get_form_fields( $source_id );
216 130
217 - $this->current_source_form = $source_form;
218 -
219 131 // If form does not contain fields, bail.
220 132 if ( empty( $source_fields ) ) {
221 133 wp_send_json_success(
222 134 array(
@@ -232,22 +144,11 @@
232 144 $this->prepare_fields( $source_fields, $form );
233 145
234 146 $this->prepare_form( $source_form, $form );
235 147
236 - $response = $this->add_form( $form );
237 -
238 - // reset
239 - $this->current_source_form = null;
240 -
241 - return $response;
148 + return $this->add_form( $form );
242 149 }
243 150
244 - /**
245 - * @param int|string $source_id
246 - * @param string $source_form_name
247 - *
248 - * @return array
249 - */
250 151 protected function prepare_new_form( $source_id, $source_form_name ) {
251 152 return array(
252 153 'import_form_id' => $source_id,
253 154 'fields' => array(),
@@ -257,29 +158,15 @@
257 158 'actions' => array(),
258 159 );
259 160 }
260 161
261 - /**
262 - * @param array|object $form
263 - * @param array $new_form
264 - *
265 - * @return void
266 - */
267 162 protected function prepare_form( $form, &$new_form ) {
268 163 // customize this function
269 164 }
270 165
271 - /**
272 - * @param array $fields
273 - * @param array $form
274 - *
275 - * @return void
276 - */
277 166 protected function prepare_fields( $fields, &$form ) {
278 167 $field_order = 1;
279 -
280 168 foreach ( $fields as $field ) {
281 - $field = (array) $field;
282 169
283 170 $label = $this->get_field_label( $field );
284 171 $type = $this->get_field_type( $field );
285 172
@@ -293,285 +180,87 @@
293 180 $this->response['upgrade_omit'][] = $label;
294 181 continue;
295 182 }
296 183
297 - $new_type = $this->convert_field_type( $type, $field );
298 -
299 - $new_field = FrmFieldsHelper::setup_new_vars( $new_type );
300 - $new_field['name'] = $label;
184 + $new_field = FrmFieldsHelper::setup_new_vars( $this->convert_field_type( $type ) );
185 + $new_field['name'] = $label;
301 186 $new_field['field_order'] = $field_order;
302 - $new_field['original'] = $type;
187 + $new_field['original'] = $type;
303 188
304 189 $this->prepare_field( $field, $new_field );
305 -
306 - $in_section = ! empty( $this->current_section ) && ! in_array( $new_type, $this->fields_with_end() ) && $new_type !== 'break';
307 -
308 - if ( $in_section ) {
309 - $new_field['field_options']['in_section'] = $this->current_section['id'];
310 - }
311 -
312 190 $form['fields'][] = $new_field;
313 191
314 - if ( in_array( $new_type, $this->fields_with_end() ) ) {
315 - $this->current_section = $field;
316 - } elseif ( $new_type === 'break' || $new_type === 'end_divider' ) {
317 - $this->current_section = array();
318 - }
319 -
320 - // This may occasionally skip one level/order e.g. after adding a
321 - // list field, as field_order would already be prepared to be used.
322 - ++$field_order;
323 -
324 - if ( ! empty( $new_field['fields'] ) && is_array( $new_field['fields'] ) ) {
325 - // we have (inner) fields to merge
326 -
327 - $form['fields'] = array_merge( $form['fields'], $new_field['fields'] );
328 - // set the new field_order as it would have changed
329 - $field_order = $new_field['current_order'];
330 - }
331 - }//end foreach
192 + $field_order++;
193 + }
332 194 }
333 195
334 - /**
335 - * @param array|object $field
336 - * @param array $new_field
337 - *
338 - * @return void
339 - */
340 196 protected function prepare_field( $field, &$new_field ) {
341 197 // customize this function
342 198 }
343 199
344 - /**
345 - * Add any field types that will need an end section field.
346 - *
347 - * @since 4.04.03
348 - *
349 - * @return array
350 - */
351 - protected function fields_with_end() {
352 - return array( 'divider' );
200 + protected function convert_field_type( $type ) {
201 + return $type;
353 202 }
354 203
355 204 /**
356 - * @since 4.04.03
205 + * Add the new form to the database and return AJAX data.
357 206 *
358 - * @param array $fields
207 + * @since 1.4.2
359 208 *
360 - * @return void
361 - */
362 - protected function maybe_add_end_fields( &$fields ) {
363 - $with_end = $this->fields_with_end();
364 -
365 - if ( empty( $with_end ) ) {
366 - return;
367 - }
368 -
369 - $open = array();
370 -
371 - $order = 0;
372 -
373 - foreach ( $fields as $field ) {
374 - ++$order;
375 - $type = $this->get_field_type( $field );
376 - $new_type = $this->convert_field_type( $type, $field );
377 -
378 - if ( ! in_array( $new_type, $with_end ) && $new_type !== 'break' ) {
379 - continue;
380 - }
381 -
382 - if ( ! empty( $open ) ) {
383 - $this->insert_end_section( $fields, $order );
384 - $open = array();
385 - }
386 -
387 - if ( in_array( $new_type, $with_end ) ) {
388 - $open = $field;
389 - }
390 - }
391 -
392 - if ( ! empty( $open ) ) {
393 - $this->insert_end_section( $fields, $order );
394 - }
395 - }
396 -
397 - /**
398 - * @since 4.04.03
399 - *
400 - * @param array $fields
401 - * @param int $order
402 - *
403 - * @return void
404 - */
405 - protected function insert_end_section( &$fields, &$order ) {
406 - $sub = FrmFieldsHelper::setup_new_vars( 'end_divider' );
407 - $sub['name'] = __( 'Section Buttons', 'formidable' );
408 - $subs = array( $sub );
409 - $this->insert_fields_in_array( $subs, $order, 0, $fields );
410 - ++$order;
411 - }
412 -
413 - /**
414 - * Replace the original combo field with a group.
415 - * This switches the name field to individual fields.
416 - *
417 - * @since 4.04.03
418 - *
419 - * @param array $subs
420 - * @param int $start
421 - * @param int $remove
422 - * @param array $fields
423 - *
424 - * @return void
425 - */
426 - protected function insert_fields_in_array( $subs, $start, $remove, &$fields ) {
427 - array_splice( $fields, $start, $remove, $subs );
428 - }
429 -
430 - /**
431 - * @param string $type
432 - * @param array $field
433 - * @param string $use Which field type to prefer to consider $field as.
434 - * This also eases the recursive use of the method,
435 - * particularly the overrides in child classes, as
436 - * there will be no need to rebuild the converter
437 - * array at usage locations.
438 - *
439 - * @return string
440 - */
441 - protected function convert_field_type( $type, $field = array(), $use = '' ) {
442 - if ( empty( $field ) ) {
443 - // For reverse compatibility.
444 - return $type;
445 - }
446 -
447 - return $use ? $use : $field['type'];
448 - }
449 -
450 - /**
451 - * Add the new form to the database and return AJAX data.
452 - *
453 209 * @param array $form Form to import.
454 - * @param array $upgrade_omit No field alternative.
455 - *
456 - * @return array
210 + * @param array $upgrade_omit No field alternative
457 211 */
458 - protected function add_form( $form, $upgrade_omit = array() ) {
212 + private function add_form( $form, $upgrade_omit = array() ) {
459 213
460 214 // Create empty form so we have an ID to work with.
461 - $form_id = $this->create_form( $form );
215 + $form_id = FrmForm::create(
216 + array(
217 + 'name' => $form['name'],
218 + 'description' => $form['description'],
219 + 'options' => $form['options'],
220 + 'form_key' => $form['name'],
221 + 'status' => 'published',
222 + )
223 + );
462 224
463 225 if ( empty( $form_id ) ) {
464 - return $this->form_creation_error_response( $form );
226 + return array(
227 + 'error' => true,
228 + 'name' => sanitize_text_field( $form['settings']['form_title'] ),
229 + 'msg' => esc_html__( 'There was an error while creating a new form.', 'formidable' ),
230 + );
465 231 }
466 232
467 - $this->create_fields( $form_id, $form );
468 -
469 - $this->create_emails( $form, $form_id );
470 -
471 - $this->track_import( $form['import_form_id'], $form_id );
472 -
473 - // Build and send final AJAX response!
474 - return array(
475 - 'name' => $form['name'],
476 - 'id' => $form_id,
477 - 'link' => esc_url_raw( FrmForm::get_edit_link( $form_id ) ),
478 - 'upgrade_omit' => $this->response['upgrade_omit'],
479 - );
480 - }
481 -
482 - /**
483 - * @since 4.04.03
484 - *
485 - * @param array $form parameters for the new form to be created. Only
486 - * the name key is a must. The keys are the column
487 - * names of the forms table in the DB.
488 - *
489 - * @return bool|int The ID of the newly created form or false on failure.
490 - */
491 - protected function create_form( $form ) {
492 - $form['form_key'] = $form['name'];
493 - $form['status'] = 'published';
494 -
495 - return FrmForm::create( $form );
496 - }
497 -
498 - /**
499 - * @since 4.04.03
500 - *
501 - * @param array $form
502 - *
503 - * @return array
504 - */
505 - protected function form_creation_error_response( $form ) {
506 - return array(
507 - 'error' => true,
508 - 'name' => sanitize_text_field( $form['name'] ),
509 - 'msg' => esc_html__( 'There was an error while creating a new form.', 'formidable' ),
510 - );
511 - }
512 -
513 - /**
514 - * @since 4.04.03
515 - *
516 - * @param int $form_id
517 - * @param array $form
518 - *
519 - * @return void
520 - */
521 - protected function create_fields( $form_id, &$form ) {
522 233 foreach ( $form['fields'] as $key => $new_field ) {
523 - $new_field['form_id'] = $form_id;
234 + $new_field['form_id'] = $form_id;
524 235 $form['fields'][ $key ]['id'] = FrmField::create( $new_field );
525 236 }
526 - }
527 237
528 - /**
529 - * @since 4.04.03
530 - *
531 - * @param array $form
532 - * @param int|string $form_id
533 - *
534 - * @return void
535 - */
536 - protected function create_emails( $form, $form_id ) {
238 + // create emails
537 239 foreach ( $form['actions'] as $action ) {
538 - $this->save_action( $action, $form, $form_id );
240 + $action_control = FrmFormActionsController::get_form_actions( $action['type'] );
241 + unset( $action['type'] );
242 + $new_action = $action_control->prepare_new( $form_id );
243 + foreach ( $action as $key => $value ) {
244 + if ( $key === 'post_title' ) {
245 + $new_action->post_title = $value;
246 + } else {
247 + $new_action->post_content[ $key ] = $this->replace_smart_tags( $value, $form['fields'] );
248 + }
249 + }
250 +
251 + $action_control->save_settings( $new_action );
539 252 }
540 - }
541 253
542 - /**
543 - * @since 4.04.03
544 - *
545 - * @param array $action
546 - * @param array $form
547 - * @param int $form_id
548 - *
549 - * @return int|WP_Error
550 - */
551 - protected function save_action( $action, $form, $form_id ) {
552 - /**
553 - * @var FrmFormAction
554 - */
555 - $action_control = FrmFormActionsController::get_form_actions( $action['type'] );
556 - unset( $action['type'] );
557 - $new_action = $action_control->prepare_new( $form_id );
254 + $this->track_import( $form['import_form_id'], $form_id );
558 255
559 - foreach ( $action as $key => $value ) {
560 - if ( $key === 'post_title' ) {
561 - $new_action->post_title = $value;
562 - } elseif ( $key === 'ID' ) {
563 - $new_action->ID = $value;
564 - } elseif ( $key === 'the_post_title' ) {
565 - $new_action->post_content['post_title'] = $value;
566 - } elseif ( is_string( $value ) ) {
567 - $new_action->post_content[ $key ] = $this->replace_smart_tags( $value, $form['fields'] );
568 - } else {
569 - $new_action->post_content[ $key ] = $value;
570 - }
571 - }
572 -
573 - return $action_control->save_settings( $new_action );
256 + // Build and send final AJAX response!
257 + return array(
258 + 'name' => $form['name'],
259 + 'id' => $form_id,
260 + 'link' => esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ) ),
261 + 'upgrade_omit' => $this->response['upgrade_omit'],
262 + );
574 263 }
575 264
576 265 /**
577 266 * After a form has been successfully imported we track it, so that in the
@@ -577,14 +266,12 @@
577 266 * After a form has been successfully imported we track it, so that in the
578 267 * future we can alert users if they try to import a form that has already
579 268 * been imported.
580 269 *
581 - * @param int $source_id Imported plugin form ID.
582 - * @param int $new_form_id Formidable form ID.
583 - *
584 - * @return void
270 + * @param int $source_id Imported plugin form ID
271 + * @param int $new_form_id Formidable form ID
585 272 */
586 - protected function track_import( $source_id, $new_form_id ) {
273 + private function track_import( $source_id, $new_form_id ) {
587 274
588 275 $imported = $this->get_tracked_import();
589 276
590 277 $imported[ $this->slug ][ $new_form_id ] = $source_id;
@@ -599,27 +286,18 @@
599 286 return get_option( $this->tracking, array() );
600 287 }
601 288
602 289 /**
603 - * @param int $source_id Imported plugin form ID.
290 + * @param int $source_id Imported plugin form ID
604 291 *
605 292 * @return int the ID of the created form or 0
606 293 */
607 294 private function is_imported( $source_id ) {
608 - $imported = $this->get_tracked_import();
295 + $imported = $this->get_tracked_import();
609 296 $new_form_id = 0;
610 -
611 - if ( ! isset( $imported[ $this->slug ] ) || ! in_array( $source_id, $imported[ $this->slug ] ) ) {
612 - return $new_form_id;
297 + if ( isset( $imported[ $this->slug ] ) && in_array( $source_id, $imported[ $this->slug ] ) ) {
298 + $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
613 299 }
614 -
615 - $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
616 -
617 - if ( ! empty( $new_form_id ) && empty( FrmForm::get_key_by_id( $new_form_id ) ) ) {
618 - // Allow reimport if the form was deleted.
619 - $new_form_id = 0;
620 - }
621 -
622 300 return $new_form_id;
623 301 }
624 302
625 303 /** Start functions here that should be overridden **/
@@ -630,16 +308,10 @@
630 308 protected function unsupported_field_types() {
631 309 return array();
632 310 }
633 311
634 - /**
635 - * @param string $type
636 - *
637 - * @return bool
638 - */
639 312 private function is_unsupported_field( $type ) {
640 313 $fields = $this->unsupported_field_types();
641 -
642 314 return in_array( $type, $fields, true );
643 315 }
644 316
645 317 /**
@@ -650,16 +322,10 @@
650 322 protected function skip_pro_fields() {
651 323 return array();
652 324 }
653 325
654 - /**
655 - * @param string $type
656 - *
657 - * @return bool
658 - */
659 - protected function should_skip_field( $type ) {
326 + private function should_skip_field( $type ) {
660 327 $skip_pro_fields = $this->skip_pro_fields();
661 -
662 328 return ( ! FrmAppHelper::pro_is_installed() && in_array( $type, $skip_pro_fields, true ) );
663 329 }
664 330
665 331 /**
@@ -682,20 +348,14 @@
682 348 public function get_forms() {
683 349 return array();
684 350 }
685 351
686 - /**
687 - * @param int|string $id
688 - *
689 - * @return array
690 - */
691 352 public function get_form( $id ) {
692 353 return array();
693 354 }
694 355
695 356 /**
696 - * @param array|object $source_form
697 - *
357 + * @param object|array $source_form
698 358 * @return string
699 359 */
700 360 protected function get_form_name( $source_form ) {
701 361 return __( 'Default Form', 'formidable' );
@@ -701,10 +361,9 @@
701 361 return __( 'Default Form', 'formidable' );
702 362 }
703 363
704 364 /**
705 - * @param array|object $source_form
706 - *
365 + * @param object|array|int $source_form
707 366 * @return array
708 367 */
709 368 protected function get_form_fields( $source_form ) {
710 369 return array();
@@ -710,29 +369,22 @@
710 369 return array();
711 370 }
712 371
713 372 /**
714 - * @param array $field
715 - *
373 + * @param object|array $field
716 374 * @return string
717 375 */
718 376 protected function get_field_type( $field ) {
719 - return $field['type'];
377 + return is_array( $field ) ? $field['type'] : $field->type;
720 378 }
721 379
722 380 /**
723 - * @param array $field
381 + * @param object|array $field
724 382 *
725 383 * @return string
726 384 */
727 385 protected function get_field_label( $field ) {
728 - $label = $field['label'] ?? '';
729 -
730 - if ( ! empty( $label ) ) {
731 - return $label;
732 - }
733 -
734 - $type = $this->get_field_type( $field );
386 + $type = $this->get_field_type( $field );
735 387 $label = sprintf(
736 388 /* translators: %1$s - field type */
737 389 esc_html__( '%1$s Field', 'formidable' ),
738 390 ucfirst( $type )