| @@ -64,9 +64,9 @@ | ||
| 64 | 64 | |
| 65 | 65 | $this->source_active = is_plugin_active( $this->path ); |
| 66 | 66 | |
| 67 | 67 | if ( ! $this->source_active ) { |
| 68 | - // if source plugin is not installed, do nothing | |
| 68 | + // If source plugin is not installed, do nothing | |
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $this->maybe_add_to_import_page(); |
| @@ -89,8 +89,9 @@ | ||
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | 91 | public function import_page() { |
| 92 | 92 | $forms = $this->get_forms(); |
| 93 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 93 | 94 | ?> |
| 94 | 95 | <div class="wrap"> |
| 95 | 96 | <h2 class="frm-h2"><?php echo esc_html( $this->name ); ?> Importer</h2> |
| 96 | 97 | <p class="howto">Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>.</p> |
| @@ -166,8 +167,9 @@ | ||
| 166 | 167 | </div> |
| 167 | 168 | </div> |
| 168 | 169 | </div> |
| 169 | 170 | <?php |
| 171 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 170 | 172 | } |
| 171 | 173 | |
| 172 | 174 | /** |
| 173 | 175 | * Import all forms using ajax |
| @@ -262,9 +264,9 @@ | ||
| 262 | 264 | * |
| 263 | 265 | * @return void |
| 264 | 266 | */ |
| 265 | 267 | protected function prepare_form( $form, &$new_form ) { |
| 266 | - // customize this function | |
| 268 | + // Customize this function | |
| 267 | 269 | } |
| 268 | 270 | |
| 269 | 271 | /** |
| 270 | 272 | * @param array $fields |
| @@ -279,9 +281,9 @@ | ||
| 279 | 281 | $field = (array) $field; |
| 280 | 282 | $label = $this->get_field_label( $field ); |
| 281 | 283 | $type = $this->get_field_type( $field ); |
| 282 | 284 | |
| 283 | - // check if field is unsupported. If unsupported make note and continue | |
| 285 | + // Check if field is unsupported. If unsupported make note and continue | |
| 284 | 286 | if ( $this->is_unsupported_field( $type ) ) { |
| 285 | 287 | $this->response['unsupported'][] = $label; |
| 286 | 288 | continue; |
| 287 | 289 | } |
| @@ -298,9 +300,9 @@ | ||
| 298 | 300 | $new_field['original'] = $type; |
| 299 | 301 | |
| 300 | 302 | $this->prepare_field( $field, $new_field ); |
| 301 | 303 | |
| 302 | - $in_section = ! empty( $this->current_section ) && ! in_array( $new_type, $this->fields_with_end(), true ) && $new_type !== 'break'; | |
| 304 | + $in_section = $this->current_section && ! in_array( $new_type, $this->fields_with_end(), true ) && $new_type !== 'break'; | |
| 303 | 305 | |
| 304 | 306 | if ( $in_section ) { |
| 305 | 307 | $new_field['field_options']['in_section'] = $this->current_section['id']; |
| 306 | 308 | } |
| @@ -313,18 +315,20 @@ | ||
| 313 | 315 | $this->current_section = array(); |
| 314 | 316 | } |
| 315 | 317 | |
| 316 | 318 | // This may occasionally skip one level/order e.g. after adding a |
| 317 | - // list field, as field_order would already be prepared to be used. | |
| 319 | + // List field, as field_order would already be prepared to be used. | |
| 318 | 320 | ++$field_order; |
| 319 | 321 | |
| 320 | - if ( ! empty( $new_field['fields'] ) && is_array( $new_field['fields'] ) ) { | |
| 321 | - // we have (inner) fields to merge | |
| 322 | + if ( empty( $new_field['fields'] ) || ! is_array( $new_field['fields'] ) ) { | |
| 323 | + continue; | |
| 324 | + } | |
| 322 | 325 | |
| 323 | - $form['fields'] = array_merge( $form['fields'], $new_field['fields'] ); | |
| 324 | - // set the new field_order as it would have changed | |
| 325 | - $field_order = $new_field['current_order']; | |
| 326 | - } | |
| 326 | + // we have (inner) fields to merge | |
| 327 | + | |
| 328 | + $form['fields'] = array_merge( $form['fields'], $new_field['fields'] ); | |
| 329 | + // Set the new field_order as it would have changed | |
| 330 | + $field_order = $new_field['current_order']; | |
| 327 | 331 | }//end foreach |
| 328 | 332 | } |
| 329 | 333 | |
| 330 | 334 | /** |
| @@ -333,9 +337,9 @@ | ||
| 333 | 337 | * |
| 334 | 338 | * @return void |
| 335 | 339 | */ |
| 336 | 340 | protected function prepare_field( $field, &$new_field ) { |
| 337 | - // customize this function | |
| 341 | + // Customize this function | |
| 338 | 342 | } |
| 339 | 343 | |
| 340 | 344 | /** |
| 341 | 345 | * Add any field types that will need an end section field. |
| @@ -610,9 +614,9 @@ | ||
| 610 | 614 | $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) ); |
| 611 | 615 | |
| 612 | 616 | if ( $new_form_id && ! FrmForm::get_key_by_id( $new_form_id ) ) { |
| 613 | 617 | // Allow reimport if the form was deleted. |
| 614 | - $new_form_id = 0; | |
| 618 | + return 0; | |
| 615 | 619 | } |
| 616 | 620 | |
| 617 | 621 | return $new_form_id; |
| 618 | 622 | } |