PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.26
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.26
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 +104 -3 1.6.21.6.26 View file →
@@ -28,8 +28,36 @@
28 28 */
29 29 public $data = null;
30 30
31 31 /**
32 + * Derived/formatted stats & metadata used by admin/AJAX/API responses.
33 + * Declared explicitly to avoid PHP 8.2 "dynamic property" deprecations.
34 + *
35 + * @var int
36 + */
37 + public $entries = 0;
38 +
39 + /**
40 + * @var array
41 + */
42 + public $settings = [];
43 +
44 + /**
45 + * @var int
46 + */
47 + public $views = 0;
48 +
49 + /**
50 + * @var int
51 + */
52 + public $payments = 0;
53 +
54 + /**
55 + * @var array
56 + */
57 + public $author = [];
58 +
59 + /**
32 60 * Form fields
33 61 *
34 62 * @var array
35 63 */
@@ -138,12 +166,16 @@
138 166 $field['enable_no_captcha'] = isset( $field['enable_no_captcha'] ) ? $field['enable_no_captcha'] : '';
139 167 $field['recaptcha_theme'] = isset( $field['recaptcha_theme'] ) ? $field['recaptcha_theme'] : 'light';
140 168 }
141 169
142 - $form_fields[] = apply_filters( 'weforms-get-form-field', $field );
170 + // Check if meta_key has changed when saving form compared current entries
171 + if ( isset( $field['name'] ) ) {
172 + $field['original_name'] = $field['name'];
173 + }
174 + $form_fields[] = apply_filters( 'weforms-get-form-field', $field, $this->id );
143 175 }
144 176
145 - $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields );
177 + $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields, $this->id );
146 178
147 179 return $this->form_fields;
148 180 }
149 181
@@ -270,9 +302,9 @@
270 302 public function get_settings() {
271 303 $settings = get_post_meta( $this->id, 'wpuf_form_settings', true );
272 304 $default = weforms_get_default_form_settings();
273 305
274 - return array_merge( $default, $settings );
306 + return apply_filters( 'weforms-get-form-settings', array_merge( $default, $settings ), $this->id );
275 307 }
276 308
277 309 /**
278 310 * Check if the form submission is open
@@ -364,8 +396,77 @@
364 396 * @return \WeForms_Form_Entry_Manager
365 397 */
366 398 public function entries() {
367 399 return new WeForms_Form_Entry_Manager( $this->id, $this );
400 + }
401 +
402 + /**
403 + * When a user is editing their form they may change a fields name.
404 + * This method will loop through existing entries to match the new field names.
405 + *
406 + * @since 1.6.9
407 + *
408 + * @param int $form_id
409 + * @param array $form_fields
410 + */
411 + public function maybe_update_entries( $form_fields ) {
412 + $changed_fields = $this->get_changed_fields( $form_fields );
413 + // Loop through changed fields and update entries
414 + foreach ( $changed_fields as $old => $new) {
415 + $updated_fields = $this->rename_field( $old, $new );
416 + }
417 + }
418 +
419 + /**
420 + * When a user is editing their form they may change a fields name.
421 + * This method will loop through all fields that have changed.
422 + *
423 + * @since 1.6.9
424 + *
425 + * @param int $form_id
426 + * @param array $form_fields
427 + *
428 + * @return array
429 + */
430 + public function get_changed_fields( $form_fields ) {
431 + $changed_fields = array();
432 + foreach ( $form_fields as $field ) {
433 + $org_field = $field['original_name'];
434 + // All form fields should have an original name.
435 + if ( empty( $field['original_name'] ) ) {
436 + continue;
437 + }
438 + if ( $field['name'] !== $field['original_name'] ) {
439 + $changed_fields[$field['original_name']] = $field['name'];
440 + } else {
441 + continue;
442 + }
443 + }
444 + return $changed_fields;
445 +
446 + }
447 +
448 + /**
449 + * When a user changes the field names of a form, the existing entries will need updated.
450 + * This method will loop through the existing entries and update them will the new names.
451 + *
452 + * @since 1.6.9
453 + *
454 + * @param int $form_id
455 + * @param array $form_fields
456 + *
457 + * @return array
458 + */
459 + public function rename_field ( $old, $new ) {
460 + global $wpdb;
461 +
462 + $entries = weforms_get_form_entries( $this->id );
463 +
464 + foreach ( $entries as $entry ) {
465 + $entry_id = $entry->id;
466 + $values = weforms_get_entry_meta( $entry_id );
467 + $update_keys = $wpdb->update( $wpdb->weforms_entrymeta, array( 'meta_key' => $new ), array( 'meta_key' => $old, 'weforms_entry_id' => $entry_id ) );
468 + }
368 469 }
369 470
370 471 /**
371 472 * Get number of form entries