PluginProbe
WANotifier for Forms and Actions / 2.4.5
WANotifier for Forms and Actions v2.4.5
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-fluentforms.php

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

279 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * FluentForms notifications
4 *
5 * @package Wa_Notifier
6 */
7 class Notifier_FluentForms {
8
9 /**
10 * Init.
11 */
12 public static function init() {
13 add_filter( 'notifier_notification_triggers', array( __CLASS__, 'add_triggers'), 10 );
14 }
15
16 /**
17 * Add notification triggers
18 */
19 public static function add_triggers( $existing_triggers ) {
20 $triggers = array();
21
22 $formApi = fluentFormApi('forms');
23
24 $atts = [
25 'status' => 'published',
26 'sort_column' => 'id',
27 'sort_by' => 'DESC',
28 'page' => 1,
29 ];
30
31 $forms = $formApi->forms($atts, $withFields = false);
32
33 if(is_array($forms['data'])){
34 foreach($forms['data'] as $form){
35 $trigger_id = 'fluentforms_' . $form->id;
36 $form_id = $form->id;
37 $title = $form->title;
38 $triggers[] = array(
39 'id' => $trigger_id,
40 'label' => 'Form "' . $title . '" is submitted',
41 'description' => 'Trigger notification when <b>'.$title.'</b> form is submitted.',
42 'merge_tags' => self::get_merge_tags($form->id),
43 'recipient_fields' => self::get_recipient_fields($form->id),
44 'action' => array(
45 'hook' => 'fluentform_submission_inserted',
46 'callback' => function ( $entryId, $formData, $form ) use ( $trigger_id, $form_id ) {
47 if($form->id != $form_id){
48 return;
49 }
50 Notifier_Notification_Triggers::send_trigger_request( $trigger_id, $formData );
51 },
52 'args_num' => 3,
53 )
54 );
55 }
56 }
57
58 $existing_triggers['Fluent Forms'] = $triggers;
59 return $existing_triggers;
60 }
61
62 /**
63 * Get merge tags for the current form
64 */
65 public static function get_merge_tags( $form_id ) {
66 $merge_tags = Notifier_Notification_Merge_Tags::get_merge_tags();
67
68 $fields_data = array();
69 $formApi = fluentFormApi('forms')->form($form_id);
70 $form_fields = $formApi->fields();
71 $excluded_field_types = array('custom_submit_button', 'section_break', 'custom_html','tabular_grid','repeater_field','terms_and_condition','action_hook','form_step','chained_select','save_progress_button', 'cpt_selection','shortcode');
72
73 if(is_array($form_fields)){
74 foreach($form_fields['fields'] as $key => $value){
75 if(in_array($value['element'], $excluded_field_types)){
76 continue;
77 }
78
79 if('input_name' === $value['element']){
80 foreach($value['fields'] as $sub_fkey => $sub_fvalue){
81 $field_type = $sub_fvalue['attributes']['type'];
82 $field_lbl = $sub_fvalue['settings']['label'];
83 $field_name = $sub_fvalue['attributes']['name'];
84
85 $fields_data[$value['attributes']['name']]['type'] = $field_type;
86 $fields_data[$value['attributes']['name']]['label'] = $value['settings']['admin_field_label'];
87 $fields_data[$value['attributes']['name']][$sub_fkey] = [
88 'label' => $field_lbl
89 ];
90 }
91 }else if('container' === $value['element']){
92 if(!empty($value['columns']) && is_array($value['columns'])){
93 foreach($value['columns'] as $col_key => $col_value){
94 foreach($col_value['fields'] as $ckey => $cval){
95
96 if(in_array($cval['element'], $excluded_field_types)){
97 continue;
98 }
99
100 $field_type = $cval['attributes']['type'];
101 $field_lbl = !empty($cval['settings']['label'])?$cval['settings']['label']:'Field_'.$cval['attributes']['name'];
102 $field_name = $cval['attributes']['name'];
103 if('input_image' == $cval['element']){
104 $field_type = 'image';
105 }
106
107 if($field_name == 'names') {
108 foreach($cval['fields'] as $field_key => $field_val){
109 $field_type = $field_val['attributes']['type'];
110 $field_name = $field_val['attributes']['name'];
111 $field_lbl = $field_val['settings']['label'];
112
113 $fields_data[$cval['attributes']['name']]['type'] = $field_type;
114 $fields_data[$cval['attributes']['name']]['label'] = $cval['settings']['admin_field_label'];
115 $fields_data[$cval['attributes']['name']][$field_key] = [
116 'label' => $field_lbl
117 ];
118 }
119 }else{
120 $fields_data[$field_name] = [
121 'label' => $field_lbl,
122 'type' => $field_type,
123 ];
124 }
125 }
126 }
127 }
128 }else if('input_image' === $value['element']) {
129 $field_type = 'image';
130 $field_name = $value['attributes']['name'];
131
132 if(!empty($value['settings']['label'])){
133 $field_lbl = $value['settings']['label'];
134 }else if(!empty($value['settings']['admin_field_label'])){
135 $field_lbl = $value['settings']['admin_field_label'];
136 }else{
137 $field_lbl = 'Field_'.$value['attributes']['name'];
138 }
139
140 $fields_data[$field_name] = [
141 'label' => $field_lbl,
142 'type' => $field_type,
143 ];
144 }else {
145 $field_type = !empty($value['attributes']['type'])?$value['attributes']['type']:'text';
146 $field_name = $value['attributes']['name'];
147
148 if(!empty($value['settings']['label'])){
149 $field_lbl = $value['settings']['label'];
150 }else if(!empty($value['settings']['admin_field_label'])){
151 $field_lbl = $value['settings']['admin_field_label'];
152 }else{
153 $field_lbl = 'lbl_'.$value['attributes']['name'];
154 }
155
156 $fields_data[$field_name] = [
157 'label' => $field_lbl,
158 'type' => $field_type,
159 ];
160 }
161 }
162 }
163
164 if(is_array($fields_data) && !empty($fields_data)){
165 foreach($fields_data as $field_key => $field_value){
166
167 $field_name = $field_value['name'];
168 $field_label = $field_value['label'];
169 $field_type = $field_value['type'];
170 if($field_type == 'image'){
171 $return_type = 'image';
172 }else{
173 $return_type = 'text';
174 }
175
176
177 $merge_tags['Fluent Forms'][] = array(
178 'id' => 'fluentforms_' . $form_id . '_' . $field_key,
179 'label' => ucfirst(str_replace('_',' ',$field_label)),
180 'preview_value' => '',
181 'return_type' => $return_type,
182 'value' => function ( $formData ) use ( $field_key ) {
183 $value = isset($formData[$field_key]) ? $formData[$field_key] : '';
184 if(is_array($value)){
185 $value = implode(', ', $value);
186 }
187 return html_entity_decode(sanitize_text_field($value));
188 }
189 );
190 }
191 }
192
193 return $merge_tags;
194 }
195
196 /*
197 * Get recipient fields
198 */
199 public static function get_recipient_fields( $form_id ){
200 $recipient_fields = array();
201 $fields_data = array();
202 $formApi = fluentFormApi('forms')->form($form_id);
203 $form_fields = $formApi->fields();
204 $excluded_field_types = array('custom_submit_button', 'section_break', 'custom_html','tabular_grid','repeater_field','terms_and_condition','action_hook','form_step','chained_select','save_progress_button', 'cpt_selection', 'shortcode');
205
206 if(is_array($form_fields)){
207 foreach($form_fields['fields'] as $key => $value){
208 if(in_array($value['element'], $excluded_field_types)){
209 continue;
210 }
211
212 if('container' === $value['element']){
213 if(!empty($value['columns']) && is_array($value['columns'])){
214 foreach($value['columns'] as $col_key => $col_value){
215 foreach($col_value['fields'] as $ckey => $cval){
216
217 if(in_array($cval['element'], $excluded_field_types)){
218 continue;
219 }
220
221 $field_type = $cval['attributes']['type'];
222 if('tel' == $field_type){
223 $field_lbl = !empty($cval['settings']['label'])?$cval['settings']['label']:'Field_'.$cval['attributes']['name'];
224 $field_name = $cval['attributes']['name'];
225
226 $fields_data[$field_name] = [
227 'label' => $field_lbl,
228 'type' => $field_type,
229 ];
230 }
231 }
232 }
233 }
234 }else {
235 $field_type = $value['attributes']['type'];
236 if('tel' == $field_type){
237 $field_name = $value['attributes']['name'];
238
239 if(!empty($value['settings']['label'])){
240 $field_lbl = $value['settings']['label'];
241 }else if(!empty($value['settings']['admin_field_label'])){
242 $field_lbl = $value['settings']['admin_field_label'];
243 }else{
244 $field_lbl = 'lbl_'.$value['attributes']['name'];
245 }
246
247 $fields_data[$field_name] = [
248 'label' => $field_lbl,
249 'type' => $field_type,
250 ];
251 }
252 }
253 }
254 }
255
256 if(is_array($fields_data) && !empty($fields_data)){
257 foreach($fields_data as $field_key => $field_value){
258 if('tel' != $field_value['type']){
259 continue;
260 }
261
262 $field_name = $field_value['name'];
263 $field_label = $field_value['label'];
264
265 $recipient_fields['Fluent Forms'][] = array(
266 'id' => 'fluentforms_' . $form_id . '_' . $field_key,
267 'label' => ucfirst(str_replace('_',' ',$field_label)),
268 'value' => function ( $formData ) use ( $field_key ) {
269 $value = isset($formData[$field_key]) ? $formData[$field_key] : '';
270 return html_entity_decode(sanitize_text_field($value));
271 }
272 );
273 }
274 }
275
276 return $recipient_fields;
277 }
278 }
279