Skip to content

Commit 54cc446

Browse files
authored
Merge branch 'master' into issue-108
2 parents 7983263 + a4d7b91 commit 54cc446

File tree

7 files changed

+779
-982
lines changed

7 files changed

+779
-982
lines changed

assets/js-templates/spa-components.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script type="text/x-template" id="tmpl-wpuf-component-table">
1+
<script type="text/x-template" id="tmpl-wpuf-component-table">
22
<div>
33

44
<div class="tablenav top">
@@ -161,9 +161,9 @@
161161
</div>
162162
</div>
163163
</div>
164-
</script>
165-
166-
<script type="text/x-template" id="tmpl-wpuf-entries">
164+
</script>
165+
166+
<script type="text/x-template" id="tmpl-wpuf-entries">
167167
<div class="wpuf-contact-form-entries">
168168
<div>
169169
<h1 class="wp-heading-inline">
@@ -219,9 +219,9 @@
219219
</div>
220220

221221
</div>
222-
</script>
223-
224-
<script type="text/x-template" id="tmpl-wpuf-form-builder">
222+
</script>
223+
224+
<script type="text/x-template" id="tmpl-wpuf-form-builder">
225225
<form id="wpuf-form-builder" class="wpuf-form-builder-contact_form" method="post" action="" @submit.prevent="save_form_builder" v-cloak>
226226
<fieldset :class="[is_form_saving ? 'disabled' : '']" :disabled="is_form_saving">
227227

@@ -333,9 +333,9 @@
333333
<input type="hidden" name="wpuf_form_id" :value="post.ID">
334334
</fieldset>
335335
</form><!-- #wpuf-form-builder -->
336-
</script>
337-
338-
<script type="text/x-template" id="tmpl-wpuf-form-entries">
336+
</script>
337+
338+
<script type="text/x-template" id="tmpl-wpuf-form-entries">
339339
<div class="wpuf-contact-form-entries">
340340
<div>
341341
<h1 class="wp-heading-inline">
@@ -388,9 +388,9 @@
388388
</div>
389389

390390
</div>
391-
</script>
392-
393-
<script type="text/x-template" id="tmpl-wpuf-form-entry-single">
391+
</script>
392+
393+
<script type="text/x-template" id="tmpl-wpuf-form-entry-single">
394394
<div class="wpuf-contact-form-entry">
395395
<h1 class="wp-heading-inline"><?php _e( 'Entry Details', 'weforms' ); ?></h1>
396396
<router-link class="page-title-action" :to="{ name: 'formEntries', params: { id: $route.params.id }}"><?php _e( 'Back to Entries', 'weforms' ); ?></router-link>
@@ -569,9 +569,9 @@
569569
</div>
570570
</div>
571571
</div>
572-
</script>
573-
574-
<script type="text/x-template" id="tmpl-wpuf-form-list-table">
572+
</script>
573+
574+
<script type="text/x-template" id="tmpl-wpuf-form-list-table">
575575
<div class="content table-responsive table-full-width" style="margin-top: 20px;">
576576

577577
<div class="tablenav top">
@@ -752,9 +752,9 @@
752752
</div>
753753
</div>
754754
</div>
755-
</script>
756-
757-
<script type="text/x-template" id="tmpl-wpuf-form-payments">
755+
</script>
756+
757+
<script type="text/x-template" id="tmpl-wpuf-form-payments">
758758
<div class="wpuf-contact-form-payments">
759759
<h1 class="wp-heading-inline">
760760
<?php _e( 'Transactions', 'weforms' ); ?>
@@ -773,19 +773,19 @@
773773
>
774774
</wpuf-table>
775775

776-
</div></script>
777-
778-
<script type="text/x-template" id="tmpl-wpuf-home-page">
776+
</div></script>
777+
778+
<script type="text/x-template" id="tmpl-wpuf-home-page">
779779
<div class="contact-form-list">
780780
<h1 class="wp-heading-inline"><?php _e( 'All Forms', 'weforms' ); ?></h1>
781781
<a class="page-title-action add-form" herf="#" v-on:click.prevent="displayModal()"><?php _e( 'Add Form', 'weforms' ); ?></a>
782782

783783
<wpuf-template-modal :show.sync="showTemplateModal" :onClose="closeModal"></wpuf-template-modal>
784784

785785
<form-list-table></form-list-table>
786-
</div></script>
787-
788-
<script type="text/x-template" id="tmpl-wpuf-tools">
786+
</div></script>
787+
788+
<script type="text/x-template" id="tmpl-wpuf-tools">
789789
<div class="export-import-wrap">
790790

791791
<h2 class="nav-tab-wrapper">
@@ -971,9 +971,9 @@
971971
</div>
972972
</div>
973973
</div>
974-
</script>
975-
976-
<script type="text/x-template" id="tmpl-wpuf-transactions">
974+
</script>
975+
976+
<script type="text/x-template" id="tmpl-wpuf-transactions">
977977
<div class="wpuf-contact-form-transactions">
978978
<h1 class="wp-heading-inline">
979979
<?php _e( 'Transactions', 'weforms' ); ?>
@@ -990,7 +990,7 @@
990990
<p v-if="no_transactions">
991991
<?php printf(
992992
__( 'You don\'t have any transactions yet. Learn how to %sset up payment integration%s and take payments with weFroms.' ),
993-
'<a target="_blank" href="https://wedevs.com/docs/weforms/integrations/payment/">',
993+
'<a target="_blank" href="https://weformspro.com/docs/modules/payment/">',
994994
'</a>'
995995
);
996996
?>
@@ -1006,9 +1006,9 @@
10061006
</wpuf-table>
10071007

10081008
</div>
1009-
</script>
1010-
1011-
<script type="text/x-template" id="tmpl-wpuf-weforms-page-help">
1009+
</script>
1010+
1011+
<script type="text/x-template" id="tmpl-wpuf-weforms-page-help">
10121012
<div class="weforms-help-page">
10131013

10141014
<div class="help-block">
@@ -1061,9 +1061,9 @@
10611061
<a target="_blank" class="button button-primary" href="https://wordpress.org/support/plugin/weforms/reviews/?rate=5#new-post"><?php _e( 'Review Us on WP.org', 'weforms' ); ?></a>
10621062
</div>
10631063
</div>
1064-
</script>
1065-
1066-
<script type="text/x-template" id="tmpl-wpuf-weforms-page-privacy">
1064+
</script>
1065+
1066+
<script type="text/x-template" id="tmpl-wpuf-weforms-page-privacy">
10671067
<div class="wpuf-privacy-page">
10681068

10691069
<h1><?php _e('Privacy' , 'weforms'); ?></h1>
@@ -1090,9 +1090,9 @@
10901090
<li><?php _e( '"Edit" the consent checkbox, remove the &#39;Field Label&#39;, and replace &#39;Option&#39; with &#39;INSERT YOUR "I AGREE" LANGUAGE HERE AND PROVIDE A LINK TO YOUR PRIVACY POLICY&#39;.' , 'weforms' ); ?></li>
10911091
</ol>
10921092

1093-
</div></script>
1094-
1095-
<script type="text/x-template" id="tmpl-wpuf-weforms-premium">
1093+
</div></script>
1094+
1095+
<script type="text/x-template" id="tmpl-wpuf-weforms-premium">
10961096
<div class="weforms-premium">
10971097
<?php
10981098
// _e( 'weForms Pro', 'weforms' );
@@ -1353,9 +1353,9 @@
13531353
</section><!-- end footer section -->
13541354

13551355
</div>
1356-
</script>
1357-
1358-
<script type="text/x-template" id="tmpl-wpuf-weforms-settings">
1356+
</script>
1357+
1358+
<script type="text/x-template" id="tmpl-wpuf-weforms-settings">
13591359
<div class="weforms-settings clearfix" id="weforms-settings">
13601360

13611361
<h1><?php _e( 'Settings', 'weforms' ); ?></h1>
@@ -1427,4 +1427,4 @@
14271427

14281428
<?php } ?>
14291429
</div>
1430-
</script>
1430+
</script>

assets/js/utils/vendor-assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
module.exports = [
6-
'assets/wpuf/vendor/vue/vue.js',
6+
'assets/wpuf/vendor/vue/vue.min.js',
77
'assets/wpuf/vendor/vuex/vuex.js',
88
'assets/js/vendor/vue-router.js',
99
'assets/js/vendor/nprogress.js',

includes/class-ajax.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ public function save_form() {
132132

133133
$form_fields = weforms()->form->save( $data );
134134

135+
// Update Old Entry meta_key if changed
136+
$form_id = $form_data['wpuf_form_id'];
137+
$form = weforms()->form->get( $form_id );
138+
139+
$form->maybe_update_entries( $form_fields );
140+
135141
do_action( 'weforms_update_form', $form_data['wpuf_form_id'], $form_fields, $settings );
136142

137143
wp_send_json_success( [ 'form_fields' => $form_fields ] );

includes/class-form.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public function get_fields() {
139139
$field['recaptcha_theme'] = isset( $field['recaptcha_theme'] ) ? $field['recaptcha_theme'] : 'light';
140140
}
141141

142+
// Check if meta_key has changed when saving form compared current entries
143+
$field['original_name'] = $field['name'];
144+
142145
$form_fields[] = apply_filters( 'weforms-get-form-field', $field, $this->id );
143146
}
144147

@@ -367,6 +370,76 @@ public function entries() {
367370
return new WeForms_Form_Entry_Manager( $this->id, $this );
368371
}
369372

373+
/**
374+
* When a user is editing their form they may change a fields name.
375+
* This method will loop through existing entries to match the new field names.
376+
*
377+
* @since 1.6.9
378+
*
379+
* @param int $form_id
380+
* @param array $form_fields
381+
*/
382+
public function maybe_update_entries( $form_fields ) {
383+
$changed_fields = $this->get_changed_fields( $form_fields );
384+
// Loop through changed fields and update entries
385+
foreach ( $changed_fields as $old => $new) {
386+
$updated_fields = $this->rename_field( $old, $new );
387+
}
388+
}
389+
390+
/**
391+
* When a user is editing their form they may change a fields name.
392+
* This method will loop through all fields that have changed.
393+
*
394+
* @since 1.6.9
395+
*
396+
* @param int $form_id
397+
* @param array $form_fields
398+
*
399+
* @return array
400+
*/
401+
public function get_changed_fields( $form_fields ) {
402+
$changed_fields = array();
403+
foreach ( $form_fields as $field ) {
404+
$org_field = $field['original_name'];
405+
error_log("Org Field" . " = " . print_r($org_field,1));
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+
}
441+
}
442+
370443
/**
371444
* Get number of form entries
372445
*

includes/functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ function weforms_get_form_payments( $form_id, $args = [] ) {
164164
return $results;
165165
}
166166

167+
/**
168+
* Get payments by a entry_id
169+
*
170+
* @param int $entry_id
171+
*
172+
* @return object
173+
*/
174+
function weforms_get_entry_payment( $entry_id ) {
175+
global $wpdb;
176+
177+
$query = 'SELECT transaction_id FROM ' . $wpdb->prefix . 'weforms_payments' .
178+
' WHERE entry_id = ' . $entry_id;
179+
$payment = $wpdb->get_row( $query, $entry_id );
180+
181+
return $payment;
182+
}
183+
167184
/**
168185
* Get an entry by id
169186
*

0 commit comments

Comments
 (0)