PluginProbe
WANotifier for Forms and Actions / trunk
WANotifier for Forms and Actions vtrunk
3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 1.0.3 All 66 releases
notifier / includes / classes / integrations / class-notifier-formidable.php

class-notifier-formidable.php in WANotifier for Forms and Actions trunk, at includes/classes/integrations/class-notifier-formidable.php

140 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 /**
7 * Formidable Form notifications
8 *
9 * @package Wa_Notifier
10 */
11 class Notifier_Formidable {
12
13 /**
14 * Init.
15 */
16 public static function init() {
17 add_filter( 'notifier_notification_triggers', array( __CLASS__, 'add_triggers'), 10 );
18 }
19
20 /**
21 * Add notification triggers
22 */
23 public static function add_triggers($existing_triggers) {
24 $triggers = array();
25 $forms = FrmForm::getall();
26
27 if(is_array($forms)){
28 foreach($forms as $form){
29 $form_id = $form->id;
30 $title = $form->name;
31 $trigger_id = 'formidableforms_' . $form_id;
32
33 $triggers[] = array(
34 'id' => $trigger_id,
35 'label' => 'Form "' . $title . '" is submitted',
36 'description' => 'Trigger notification when <b>'.$title.'</b> form is submitted.',
37 'merge_tags' => self::get_merge_tags($form_id),
38 'recipient_fields' => self::get_recipient_fields($form_id),
39 'action' => array(
40 'hook' => 'frm_after_create_entry',
41 'callback' => function ( $entry_id, $form_id ) use ( $trigger_id ) {
42 $trigger_form_id = str_replace('formidableforms_', '', $trigger_id);
43 if($form_id != $trigger_form_id){
44 return;
45 }
46
47 $sanitized_data = array();
48 foreach($_POST['item_meta'] as $key => $data){
49 if(is_array($data)){
50 $sanitized_data[$key] = notifier_sanitize_array($data);
51 }
52 else{
53 $sanitized_data[$key] = sanitize_text_field($data);
54 }
55 }
56
57 Notifier_Notification_Triggers::send_trigger_request( $trigger_id, $sanitized_data );
58 },
59 'args_num' => 2,
60 )
61 );
62 }
63 }
64
65 $existing_triggers['Formidable Forms'] = $triggers;
66 return $existing_triggers;
67 }
68
69 /**
70 * Get merge tags for the current form
71 */
72 public static function get_merge_tags( $form_id ) {
73
74 $merge_tags = Notifier_Notification_Merge_Tags::get_merge_tags();
75 $formidableforms_fields = FrmField::get_all_for_form( $form_id );
76
77 $excluded_field_types = array('submit', 'captcha', 'spam', 'hr', 'repeater', 'html');
78 $form_fields = $formidableforms_fields;
79
80
81 if(is_array($form_fields)){
82 foreach($form_fields as $field){
83
84 if(in_array($field->type, $excluded_field_types)){
85 continue;
86 }
87
88 $field_name = $field->type;
89 $field_id = $field->id;
90 $return_type = 'text';
91
92 $merge_tags['Formidable Forms'][] = array(
93 'id' => 'formidableforms_' . $form_id . '_' . $field_id,
94 'label' => $field_name,
95 'preview_value' => '',
96 'return_type' => $return_type,
97 'value' => function ( $sanitized_data ) use ( $field_id ) {
98 $value = isset($sanitized_data[$field_id]) ? $sanitized_data[$field_id] : '';
99 if(is_array($value)){
100 $value = implode(', ', $value);
101 }
102 return html_entity_decode(sanitize_text_field($value));
103 }
104 );
105 }
106 }
107 return $merge_tags;
108 }
109
110 /*
111 * Get recipient fields
112 */
113 public static function get_recipient_fields( $form_id ){
114 $formidableforms_fields = FrmField::get_all_for_form( $form_id );
115 $form_fields = $formidableforms_fields;
116 $recipient_fields = array();
117
118 if(is_array($form_fields)){
119 foreach($form_fields as $field){
120 if('phone' != $field->type){
121 continue;
122 }
123
124 $field_name = $field->name;
125 $field_id = $field->id;
126
127 $recipient_fields['Formidable Forms'][] = array(
128 'id' => 'formidableforms_' . $form_id . '_' . $field_id,
129 'label' => $field_name,
130 'value' => function ( $sanitized_data ) use ( $field_id ) {
131 $value = isset($sanitized_data[$field_id]) ? $sanitized_data[$field_id] : '';
132 return html_entity_decode(sanitize_text_field($value));
133 }
134 );
135 }
136 }
137 return $recipient_fields;
138 }
139 }
140