PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.24
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.24
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/class-form.php +76 -3 1.6.41.6.24 View file →
@@ -138,12 +138,16 @@
138 138 $field['enable_no_captcha'] = isset( $field['enable_no_captcha'] ) ? $field['enable_no_captcha'] : '';
139 139 $field['recaptcha_theme'] = isset( $field['recaptcha_theme'] ) ? $field['recaptcha_theme'] : 'light';
140 140 }
141 141
142 - $form_fields[] = apply_filters( 'weforms-get-form-field', $field );
142 + // Check if meta_key has changed when saving form compared current entries
143 + if ( isset( $field['name'] ) ) {
144 + $field['original_name'] = $field['name'];
145 + }
146 + $form_fields[] = apply_filters( 'weforms-get-form-field', $field, $this->id );
143 147 }
144 148
145 - $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields );
149 + $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields, $this->id );
146 150
147 151 return $this->form_fields;
148 152 }
149 153
@@ -270,9 +274,9 @@
270 274 public function get_settings() {
271 275 $settings = get_post_meta( $this->id, 'wpuf_form_settings', true );
272 276 $default = weforms_get_default_form_settings();
273 277
274 - return array_merge( $default, $settings );
278 + return apply_filters( 'weforms-get-form-settings', array_merge( $default, $settings ), $this->id );
275 279 }
276 280
277 281 /**
278 282 * Check if the form submission is open
@@ -364,8 +368,77 @@
364 368 * @return \WeForms_Form_Entry_Manager
365 369 */
366 370 public function entries() {
367 371 return new WeForms_Form_Entry_Manager( $this->id, $this );
372 + }
373 +
374 + /**
375 + * When a user is editing their form they may change a fields name.
376 + * This method will loop through existing entries to match the new field names.
377 + *
378 + * @since 1.6.9
379 + *
380 + * @param int $form_id
381 + * @param array $form_fields
382 + */
383 + public function maybe_update_entries( $form_fields ) {
384 + $changed_fields = $this->get_changed_fields( $form_fields );
385 + // Loop through changed fields and update entries
386 + foreach ( $changed_fields as $old => $new) {
387 + $updated_fields = $this->rename_field( $old, $new );
388 + }
389 + }
390 +
391 + /**
392 + * When a user is editing their form they may change a fields name.
393 + * This method will loop through all fields that have changed.
394 + *
395 + * @since 1.6.9
396 + *
397 + * @param int $form_id
398 + * @param array $form_fields
399 + *
400 + * @return array
401 + */
402 + public function get_changed_fields( $form_fields ) {
403 + $changed_fields = array();
404 + foreach ( $form_fields as $field ) {
405 + $org_field = $field['original_name'];
406 + // All form fields should have an original name.
407 + if ( empty( $field['original_name'] ) ) {
408 + continue;
409 + }
410 + if ( $field['name'] !== $field['original_name'] ) {
411 + $changed_fields[$field['original_name']] = $field['name'];
412 + } else {
413 + continue;
414 + }
415 + }
416 + return $changed_fields;
417 +
418 + }
419 +
420 + /**
421 + * When a user changes the field names of a form, the existing entries will need updated.
422 + * This method will loop through the existing entries and update them will the new names.
423 + *
424 + * @since 1.6.9
425 + *
426 + * @param int $form_id
427 + * @param array $form_fields
428 + *
429 + * @return array
430 + */
431 + public function rename_field ( $old, $new ) {
432 + global $wpdb;
433 +
434 + $entries = weforms_get_form_entries( $this->id );
435 +
436 + foreach ( $entries as $entry ) {
437 + $entry_id = $entry->id;
438 + $values = weforms_get_entry_meta( $entry_id );
439 + $update_keys = $wpdb->update( $wpdb->weforms_entrymeta, array( 'meta_key' => $new ), array( 'meta_key' => $old, 'weforms_entry_id' => $entry_id ) );
440 + }
368 441 }
369 442
370 443 /**
371 444 * Get number of form entries