PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.4
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
weforms / includes / importer / class-importer-abstract.php

class-importer-abstract.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.0.4, at includes/importer/class-importer-abstract.php

874 lines 30.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Importer Abstract Class
5 */
6 abstract class WeForms_Importer_Abstract {
7
8 /**
9 * The importer ID
10 *
11 * @var string
12 */
13 public $id = '';
14
15 /**
16 * The importer title
17 *
18 * @var string
19 */
20 public $title = '';
21
22 /**
23 * The shortcode (without bracket)
24 *
25 * @var string
26 */
27 public $shortcode = '';
28
29 /**
30 * The ajax action string
31 *
32 * @var string
33 */
34 protected $action = '';
35
36 /**
37 * Conditional stub
38 *
39 * @var array
40 */
41 public $conditionals = array(
42 'condition_status' => 'no',
43 'cond_field' => array(),
44 'cond_operator' => array( '=' ),
45 'cond_option' => array( '- select -' ),
46 'cond_logic' => 'all'
47 );
48
49 public function __construct() {
50 add_action( 'admin_notices', array( $this, 'maybe_show_notice' ) );
51
52 add_action( 'wp_ajax_weforms_import_xdismiss_' . $this->id, array( $this, 'dismiss_notice' ) );
53 add_action( 'wp_ajax_weforms_import_xforms_' . $this->id, array( $this, 'import_forms' ) );
54 add_action( 'wp_ajax_weforms_import_xreplace_' . $this->id, array( $this, 'replace_action' ) );
55 }
56
57 /**
58 * Get the importer name
59 *
60 * @return string
61 */
62 public function get_importer_name() {
63 return $this->title;
64 }
65
66 /**
67 * Get the shortcode ready for regular expression
68 *
69 * @return string
70 */
71 public function get_shortcode( $regex = false ) {
72
73 if ( $regex ) {
74 return preg_quote( $this->shortcode );
75 }
76
77 return $this->shortcode;
78 }
79
80 /**
81 * Get all the forms
82 *
83 * @return array
84 */
85 abstract protected function get_forms();
86
87 /**
88 * Get the form name
89 *
90 * @param mixed $form
91 *
92 * @return string
93 */
94 abstract protected function get_form_name( $form );
95
96 /**
97 * Get the form id
98 *
99 * @param mixed $form
100 *
101 * @return int
102 */
103 abstract protected function get_form_id( $form );
104
105 /**
106 * Get all form fields of a form
107 *
108 * @param mixed $form
109 *
110 * @return array
111 */
112 abstract protected function get_form_fields( $form );
113
114 /**
115 * Get form settings of a form
116 *
117 * @param mixed $form
118 *
119 * @return array
120 */
121 abstract protected function get_form_settings( $form );
122
123 /**
124 * Get form notifications of a form
125 *
126 * @param mixed $form
127 *
128 * @return array
129 */
130 abstract protected function get_form_notifications( $form );
131
132 /**
133 * Check if the plugin exists
134 *
135 * @return boolean
136 */
137 abstract protected function plugin_exists();
138
139 /**
140 * Show notice if the plugin found
141 *
142 * @return void
143 */
144 public function maybe_show_notice() {
145 if ( ! $this->plugin_exists() ) {
146 return;
147 }
148
149 if ( $this->is_dimissed() || !current_user_can( 'manage_options' ) ) {
150 return;
151 }
152
153 ?>
154 <div class="notice notice-info">
155 <p><strong><?php printf( __( '%s Detected', 'weforms' ), $this->get_importer_name() ); ?></strong></p>
156 <p><?php printf( __( 'Hey, looks like you have <strong>%s</strong> installed. Would you like to <strong>import</strong> the forms into weForms?', 'weforms' ), $this->get_importer_name() ); ?></p>
157
158 <p>
159 <a href="#" class="button button-primary weforms-import-<?php echo $this->id ;?>" id="weforms-import-<?php echo $this->id ;?>"><?php _e( 'Import Forms', 'weforms' ); ?></a>
160 <a href="#" class="button weforms-import-<?php echo $this->id ;?>" id="weforms-dimiss-<?php echo $this->id ;?>"><?php _e( 'No Thanks', 'weforms' ); ?></a>
161 </p>
162 </div>
163
164 <script type="text/javascript">
165 jQuery(function($) {
166 $('.notice').on('click', 'a#weforms-import-<?php echo $this->id ;?>', function(e) {
167 e.preventDefault();
168
169 var self = $(this);
170 self.addClass('updating-message');
171
172 wp.ajax.send( 'weforms_import_xforms_<?php echo $this->id ;?>', {
173 data: {
174 type: self.data('type'),
175 _wpnonce: '<?php echo wp_create_nonce( 'weforms' ); ?>'
176 },
177
178 success: function(response) {
179 var html = '<p><strong>' + response.title + '</strong></p>' +
180 '<p>' + response.message + '</p>' +
181 '<p>' + response.action + '</p>';
182
183 html += '<ul>';
184 _.each(response.refs, function(el, index) {
185 html += '<li><a target="_blank" href="admin.php?page=weforms#/form/' + el.weforms_id + '/edit">' + el.title + '</a> - <a href="admin.php?page=weforms#/form/' + el.weforms_id + '/edit" target="_blank" class="button button-small"><span class="dashicons dashicons-external"></span> Edit</a></li>';
186 });
187
188 html += '</ul>';
189 html += '<p>' + '<a href="#" class="button button-primary weforms-<?php echo $this->id ;?>-replace-action" data-type="replace"><?php _e( 'Replace Shortcodes', 'weforms' ); ?></a>&nbsp;' +
190 '<a href="#" class="button weforms-<?php echo $this->id ;?>-replace-action" data-type="skip"><?php _e( 'No Thanks', 'weforms' ); ?></a></p>';
191
192 self.closest('.notice').removeClass('notice-info').addClass('notice-success').html( html );
193 },
194
195 error: function(error) {
196 var html = '<p><strong>' + error.title + '</strong></p>' +
197 '<p>' + error.message + '</p>';
198
199 self.closest('.notice').removeClass('notice-info').addClass('notice-error').html( html );
200 },
201
202 complete: function() {
203 self.removeClass('updating-message');
204 }
205 });
206 });
207
208 $('.notice').on('click', '#weforms-dimiss-<?php echo $this->id ;?>', function(e) {
209 e.preventDefault();
210
211 $(this).closest('.notice').remove();
212 wp.ajax.send('weforms_import_xdismiss_<?php echo $this->id ;?>');
213 });
214
215 $('.notice').on('click', 'a.weforms-<?php echo $this->id ;?>-replace-action', function(e) {
216 e.preventDefault();
217
218 var self = $(this);
219 var notice = self.closest('.notice');
220
221 self.addClass('updating-message');
222
223 wp.ajax.send( 'weforms_import_xreplace_<?php echo $this->id ;?>', {
224 data: {
225 type: self.data('type'),
226 _wpnonce: '<?php echo wp_create_nonce( 'weforms' ); ?>'
227 },
228
229 success: function(response) {
230 notice.remove();
231
232 if ( 'replace' === self.data('type') ) {
233 alert( response );
234 }
235 },
236
237 error: function(error) {
238 notice.remove();
239 alert( error );
240 },
241
242 complete: function() {
243 self.removeClass('updating-message');
244 }
245 });
246
247 });
248 });
249 </script>
250 <?php
251 }
252
253 /**
254 * Import forms
255 *
256 * @return void
257 */
258 public function import_forms() {
259 check_ajax_referer( 'weforms' );
260
261 $this->check_caps();
262
263 // check if plugin installed
264 if ( ! $this->plugin_exists() ) {
265 wp_send_json_error( array(
266 'title' => __( 'Uh oh!', 'weforms' ),
267 'message' => sprintf( __( '%s is not installed.', 'weforms' ), $this->get_importer_name() )
268 ) );
269 }
270
271 $imported = 0;
272 $refs = array();
273 $forms = $this->get_forms();
274
275 if ( ! $forms ) {
276 wp_send_json_error( array(
277 'title' => __( 'Uh oh!', 'weforms' ),
278 'message' => __( 'No forms found!', 'weforms' )
279 ) );
280
281 $this->dismiss_prompt();
282 }
283
284 if ( $forms ) {
285 foreach ($forms as $form) {
286 $form_name = $this->get_form_name( $form );
287 $form_fields = $this->get_form_fields( $form );
288 $settings = $this->get_form_settings( $form );
289 $notifications = $this->get_form_notifications( $form );
290
291 error_log( print_r( $form_fields, true ) );
292
293 if ( $form_fields ) {
294 $form_id = $this->insert_form( $form_name );
295
296 if ( is_wp_error( $form_id ) ) {
297 continue;
298 }
299
300 foreach ($form_fields as $menu_order => $form_field) {
301 $this->insert_form_field( $form_field, $form_id, $menu_order );
302 }
303
304 $this->update_settings( $form_id, $settings );
305 $this->update_notification( $form_id, $notifications );
306
307 $imported++;
308
309 $refs[ $this->get_form_id( $form ) ] = array(
310 'imported_id' => $this->get_form_id( $form ),
311 'weforms_id' => $form_id,
312 'title' => $form_name
313 );
314 }
315 }
316 }
317
318 $this->dismiss_prompt();
319 $this->update_refs( $refs );
320
321 wp_send_json_success( array(
322 'title' => sprintf( _n( '%s form imported', '%s forms imported', $imported ), $imported ),
323 'message' => __( 'We have successfully imported these forms into weForms. You could check and edit in-case anything weird happended.', 'weforms' ),
324 'action' => sprintf( __( 'Do you want to <strong>replace</strong> %s shortcodes with weForms?', 'weforms' ), $this->get_importer_name() ),
325 'refs' => $refs
326 ) );
327 }
328
329 /**
330 * Replace contact form 7 shortcodes
331 *
332 * @return void
333 */
334 public function replace_action() {
335 check_ajax_referer( 'weforms' );
336
337 $this->check_caps();
338
339 if ( ! in_array( $_POST['type'], array( 'skip', 'replace' ) ) ) {
340 wp_send_json_error( __( 'Not a valid action type.', 'weforms' ) );
341 }
342
343 if ( 'skip' == $_POST['type'] ) {
344 wp_send_json_success();
345 }
346
347 $pages_query = new WP_Query( array(
348 'post_type' => 'page',
349 'posts_per_page' => -1,
350 's' => '[' . $this->get_shortcode()
351 ) );
352
353 if ( ! $pages_query->found_posts ) {
354 wp_send_json_error( __( 'No pages found with shortcode. Skipped!', 'weforms' ) );
355 }
356
357 $count = 0;
358 $refs = $this->get_refs();
359 $pages = $pages_query->get_posts();
360
361 foreach ($pages as $page) {
362 preg_match_all( '/\[(\[?)(' . $this->get_shortcode( true ) . '|)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/s', $page->post_content, $matches, PREG_SET_ORDER );
363
364 if ( empty( $matches ) ) {
365 continue;
366 }
367
368 foreach ( $matches as $shortcode ) {
369 $atts = shortcode_parse_atts( $shortcode[0] );
370
371 if ( isset( $atts['id'] ) && array_key_exists( $atts['id'], $refs ) ) {
372 $replace = sprintf( '[weforms id="%d"]', $refs[ $atts['id'] ]['weforms_id'] );
373
374 $post_content = str_replace( $shortcode[0], $replace, $page->post_content );
375
376 wp_update_post( array(
377 'ID' => $page->ID,
378 'post_content' => $post_content
379 ) );
380
381 $count++;
382 }
383 }
384 }
385
386 wp_send_json_success( sprintf( _n( 'Replaced %d form', 'Replaced %d forms', $count ), $count ) );
387 }
388
389 /**
390 * Check capability if able to process
391 *
392 * @return void
393 */
394 public function check_caps() {
395 if ( ! current_user_can( 'manage_options' ) ) {
396 wp_send_json_error( __( 'You are not allowed.', 'weforms' ) );
397 }
398 }
399
400 /**
401 * If the prompt is dismissed
402 *
403 * @return boolean
404 */
405 public function is_dimissed() {
406 return 'yes' == get_option( 'weforms_dismiss_xnotice_' . $this->id );
407 }
408
409 /**
410 * Dismiss the prompt
411 *
412 * @return void
413 */
414 public function dismiss_prompt() {
415 update_option( 'weforms_dismiss_xnotice_' . $this->id, 'yes' );
416 }
417
418 /**
419 * Dismiss the notice
420 *
421 * @return void
422 */
423 public function dismiss_notice() {
424 $this->dismiss_prompt();
425
426 wp_send_json_success();
427 }
428
429 /**
430 * Get the imported form refs
431 *
432 * @return array
433 */
434 public function get_refs() {
435 return get_option( 'weforms_imported_xforms_' . $this->id, array() );
436 }
437
438 /**
439 * Update the imported reference forms
440 *
441 * @param array $refs
442 *
443 * @return void
444 */
445 public function update_refs( $refs ) {
446 update_option( 'weforms_imported_xforms_' . $this->id, $refs );
447 }
448
449 /**
450 * Get form field
451 *
452 * @param string $type
453 * @param array $args [description]
454 *
455 * @return array
456 */
457 public function get_form_field( $type, $args = array() ) {
458 $defaults = array(
459 'required' => 'no',
460 'label' => '',
461 'name' => '',
462 'help' => '',
463 'css_class' => '',
464 'placeholder' => '',
465 'value' => '',
466 'default' => '',
467 'options' => array(),
468 'step' => '',
469 'min' => '',
470 'max' => '',
471 'extension' => '',
472 'max_size' => '', // file size
473 'size' => '', // file size
474 'first_placeholder' => '',
475 'first_default' => '',
476 'middle_placeholder' => '',
477 'middle_default' => '',
478 'last_placeholder' => '',
479 'last_default' => '',
480 );
481
482 $args = wp_parse_args( $args, $defaults );
483
484 switch ( $type ) {
485 case 'text':
486 $field_content = array(
487 'input_type' => 'text',
488 'template' => 'text_field',
489 'required' => $args['required'],
490 'label' => $args['label'],
491 'name' => $args['name'],
492 'is_meta' => 'yes',
493 'help' => $args['help'],
494 'css' => $args['css_class'],
495 'placeholder' => $args['placeholder'],
496 'default' => $args['default'],
497 'size' => $args['size'],
498 'word_restriction' => '',
499 'wpuf_cond' => $this->conditionals
500 );
501 break;
502
503 case 'email':
504 $field_content = array(
505 'input_type' => 'email',
506 'template' => 'email_address',
507 'required' => $args['required'],
508 'label' => $args['label'],
509 'name' => $args['name'],
510 'is_meta' => 'yes',
511 'help' => $args['help'],
512 'css' => $args['css_class'],
513 'placeholder' => $args['placeholder'],
514 'default' => $args['default'],
515 'size' => $args['size'],
516 'word_restriction' => '',
517 'wpuf_cond' => $this->conditionals
518 );
519 break;
520
521 case 'textarea':
522 $field_content = array(
523 'input_type' => 'textarea',
524 'template' => 'textarea_field',
525 'required' => $args['required'],
526 'label' => $args['label'],
527 'name' => $args['name'],
528 'is_meta' => 'yes',
529 'help' => $args['help'],
530 'css' => $args['css_class'],
531 'rows' => 5,
532 'cols' => 25,
533 'placeholder' => $args['placeholder'],
534 'default' => $args['default'],
535 'rich' => 'no',
536 'word_restriction' => '',
537 'wpuf_cond' => $this->conditionals
538 );
539 break;
540
541 case 'select':
542 $field_content = array(
543 'input_type' => 'select',
544 'template' => 'dropdown_field',
545 'required' => $args['required'],
546 'label' => $args['label'],
547 'name' => $args['name'],
548 'is_meta' => 'yes',
549 'help' => '',
550 'css' => $args['css_class'],
551 'selected' => '',
552 'inline' => 'no',
553 'options' => $args['options'],
554 'wpuf_cond' => $this->conditionals
555 );
556 break;
557
558 case 'multiselect':
559 $field_content = array(
560 'input_type' => 'multiselect',
561 'template' => 'multiple_select',
562 'required' => $args['required'],
563 'label' => $args['label'],
564 'name' => $args['name'],
565 'is_meta' => 'yes',
566 'help' => '',
567 'css' => $args['css_class'],
568 'selected' => '',
569 'first' => __( '- select -', 'wpuf' ),
570 'options' => $args['options'],
571 'wpuf_cond' => $this->conditionals
572 );
573 break;
574
575 case 'date':
576 $field_content = array(
577 'input_type' => 'date',
578 'template' => 'date_field',
579 'required' => $args['required'],
580 'label' => $args['label'],
581 'name' => $args['name'],
582 'is_meta' => 'yes',
583 'help' => '',
584 'css' => $args['css_class'],
585 'format' => 'dd/mm/yy',
586 'time' => '',
587 'is_publish_time' => '',
588 'wpuf_cond' => $this->conditionals
589 );
590 break;
591
592 case 'range':
593 case 'number':
594
595 $field_content = array(
596 'input_type' => 'numeric_text',
597 'template' => 'numeric_text_field',
598 'required' => $args['required'],
599 'label' => $args['label'],
600 'name' => $args['name'],
601 'is_meta' => 'yes',
602 'help' => '',
603 'css' => $args['css_class'],
604 'placeholder' => $args['placeholder'],
605 'default' => $args['value'],
606 'size' => 40,
607 'step_text_field' => $args['step'],
608 'min_value_field' => $args['min'],
609 'max_value_field' => $args['max'],
610 'wpuf_cond' => $this->conditionals
611 );
612
613 break;
614
615 case 'url':
616 $field_content = array(
617 'input_type' => 'url',
618 'template' => 'website_url',
619 'required' => $args['required'],
620 'label' => $args['label'],
621 'name' => $args['name'],
622 'is_meta' => 'yes',
623 'help' => '',
624 'css' => $args['css_class'],
625 'placeholder' => '',
626 'default' => '',
627 'size' => 40,
628 'word_restriction' => '',
629 'wpuf_cond' => $this->conditionals
630 );
631
632 break;
633
634 case 'checkbox':
635 $field_content = array(
636 'input_type' => 'checkbox',
637 'template' => 'checkbox_field',
638 'required' => $args['required'],
639 'label' => $args['label'],
640 'name' => $args['name'],
641 'is_meta' => 'yes',
642 'help' => '',
643 'css' => $args['css_class'],
644 'selected' => '',
645 'inline' => 'no',
646 'options' => $args['options'],
647 'wpuf_cond' => $this->conditionals
648 );
649 break;
650
651 case 'radio':
652 $field_content = array(
653 'input_type' => 'radio',
654 'template' => 'radio_field',
655 'required' => $args['required'],
656 'label' => $args['label'],
657 'name' => $args['name'],
658 'is_meta' => 'yes',
659 'help' => '',
660 'css' => $args['css_class'],
661 'selected' => '',
662 'inline' => 'no',
663 'options' => $args['options'],
664 'wpuf_cond' => $this->conditionals
665 );
666 break;
667
668 case 'hidden':
669 $field_content = array(
670 'input_type' => 'hidden',
671 'template' => 'custom_hidden_field',
672 'label' => $args['label'],
673 'name' => $args['name'],
674 'is_meta' => 'yes',
675 'wpuf_cond' => $this->conditionals
676 );
677 break;
678
679 case 'section_break':
680 $field_content = array(
681 'input_type' => 'section_break',
682 'template' => 'section_break',
683 'label' => $args['label'],
684 'name' => $args['name'],
685 'wpuf_cond' => $this->conditionals
686 );
687 break;
688
689 case 'html':
690 $field_content = array(
691 'input_type' => 'html',
692 'template' => 'custom_html',
693 'label' => $args['label'],
694 'name' => $args['name'],
695 'wpuf_cond' => $this->conditionals
696 );
697 break;
698
699 case 'toc':
700 $field_content = array(
701 'input_type' => 'toc',
702 'template' => 'toc',
703 'required' => $args['required'],
704 'name' => $args['name'],
705 'description' => $args['label'],
706 'is_meta' => 'yes',
707 'show_checkbox' => true,
708 'wpuf_cond' => $this->conditionals
709 );
710 break;
711
712 case 'recaptcha':
713 $field_content = array(
714 'input_type' => 'recaptcha',
715 'template' => 'recaptcha',
716 'required' => $args['required'],
717 'label' => $args['label'],
718 'name' => $args['name'],
719 'recaptcha_type' => 'enable_no_captcha',
720 'is_meta' => 'yes',
721 'help' => '',
722 'css' => $args['css_class'],
723 'placeholder' => '',
724 'default' => '',
725 'size' => 40,
726 'word_restriction' => '',
727 'wpuf_cond' => $this->conditionals
728 );
729 break;
730
731 case 'file':
732 $field_content = array(
733 'input_type' => 'file_upload',
734 'template' => 'file_upload',
735 'required' => $args['required'],
736 'label' => $args['label'],
737 'name' => $args['name'],
738 'is_meta' => 'yes',
739 'help' => '',
740 'css' => $args['css_class'],
741 'max_size' => $args['max_size'],
742 'count' => '1',
743 'extension' => $args['extension'],
744 'wpuf_cond' => $this->conditionals
745 );
746 break;
747
748 case 'name':
749 $field_content = array(
750 'input_type' => 'name',
751 'template' => 'name_field',
752 'required' => $args['required'],
753 'label' => $args['label'],
754 'name' => $args['name'],
755 'is_meta' => 'yes',
756 'format' => $args['format'],
757 'first_name' => array(
758 'placeholder' => $args['first_placeholder'],
759 'default' => $args['first_default'],
760 'sub' => __( 'First', 'weforms' )
761 ),
762 'middle_name' => array(
763 'placeholder' => $args['middle_placeholder'],
764 'default' => $args['middle_default'],
765 'sub' => __( 'Middle', 'weforms' )
766 ),
767 'last_name' => array(
768 'placeholder' => $args['last_placeholder'],
769 'default' => $args['last_default'],
770 'sub' => __( 'Last', 'weforms' )
771 ),
772 'hide_subs' => false,
773 'help' => $args['description'],
774 'css' => $args['css_class'],
775 'wpuf_cond' => $this->conditionals
776 );
777 break;
778 }
779
780 return $field_content;
781 }
782
783 /**
784 * Default form settings
785 *
786 * @return array
787 */
788 public function get_default_form_settings() {
789 $form_settings = array(
790 'redirect_to' => 'same',
791 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
792 'page_id' => '',
793 'url' => '',
794 'submit_text' => __( 'Submit Query', 'weforms' ),
795 'schedule_form' => 'false',
796 'schedule_start' => '',
797 'schedule_end' => '',
798 'sc_pending_message' => __( 'Form submission hasn\'t been started yet', 'weforms' ),
799 'sc_expired_message' => __( 'Form submission is now closed.', 'weforms' ),
800 'require_login' => 'false',
801 'req_login_message' => __( 'You need to login to submit a query.', 'weforms' ),
802 'limit_entries' => 'false',
803 'limit_number' => '1000',
804 'limit_message' => __( 'Sorry, we have reached the maximum number of submissions.', 'weforms' ),
805 'label_position' => 'above',
806 );
807
808 return $form_settings;
809 }
810
811 /**
812 * Insert a form
813 *
814 * @param string $form_name
815 *
816 * @return ID|WP_Error
817 */
818 public function insert_form( $form_name ) {
819 $weforms_form = array(
820 'post_title' => sprintf( '[%s] %s', strtoupper( $this->id ), $form_name ),
821 'post_type' => 'wpuf_contact_form',
822 'post_status' => 'publish',
823 'post_author' => get_current_user_id()
824 );
825
826 return wp_insert_post( $weforms_form );
827 }
828
829 /**
830 * Insert a form field
831 *
832 * @param array $field
833 * @param int $form_id
834 * @param int $menu_order
835 *
836 * @return int|WP_Error
837 */
838 public function insert_form_field( $field, $form_id, $menu_order ) {
839 $form_field = array(
840 'post_type' => 'wpuf_input',
841 'post_status' => 'publish',
842 'post_content' => maybe_serialize( $field ),
843 'post_parent' => $form_id,
844 'menu_order' => $menu_order
845 );
846
847 return wp_insert_post( $form_field );
848 }
849
850 /**
851 * Update form settings
852 *
853 * @param int $form_id
854 * @param array $settings
855 *
856 * @return void
857 */
858 public function update_settings( $form_id, $settings ) {
859 update_post_meta( $form_id, 'wpuf_form_settings', $settings );
860 }
861
862 /**
863 * Update Notification
864 *
865 * @param int $form_id
866 * @param array $notification
867 *
868 * @return void
869 */
870 public function update_notification( $form_id, $notifications ) {
871 update_post_meta( $form_id, 'notifications', $notifications );
872 }
873 }
874