PluginProbe
WANotifier for Forms and Actions / 2.1.2
WANotifier for Forms and Actions v2.1.2
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 / class-notifier-fluentforms.php

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

275 lines 8.5 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 $title = $form->title;
37 $triggers[] = array(
38 'id' => $trigger_id,
39 'label' => 'Form "' . $title . '" is submitted',
40 'description' => 'Trigger notification when <b>'.$title.'</b> form is submitted.',
41 'merge_tags' => self::get_merge_tags($form->id),
42 'recipient_fields' => self::get_recipient_fields($form->id),
43 'action' => array(
44 'hook' => 'fluentform_submission_inserted',
45 'callback' => function ( $entryId, $formData, $form ) use ( $trigger_id ) {
46 Notifier_Notification_Triggers::send_trigger_request( $trigger_id, $formData );
47 },
48 'args_num' => 3,
49 )
50 );
51 }
52 }
53
54 $existing_triggers['Fluent Forms'] = $triggers;
55 return $existing_triggers;
56 }
57
58 /**
59 * Get merge tags for the current form
60 */
61 public static function get_merge_tags( $form_id ) {
62 $merge_tags = Notifier_Notification_Merge_Tags::get_merge_tags();
63
64 $fields_data = array();
65 $formApi = fluentFormApi('forms')->form($form_id);
66 $form_fields = $formApi->fields();
67 $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');
68
69 if(is_array($form_fields)){
70 foreach($form_fields['fields'] as $key => $value){
71 if(in_array($value['element'], $excluded_field_types)){
72 continue;
73 }
74
75 if('input_name' === $value['element']){
76 foreach($value['fields'] as $sub_fkey => $sub_fvalue){
77 $field_type = $sub_fvalue['attributes']['type'];
78 $field_lbl = $sub_fvalue['settings']['label'];
79 $field_name = $sub_fvalue['attributes']['name'];
80
81 $fields_data[$value['attributes']['name']]['type'] = $field_type;
82 $fields_data[$value['attributes']['name']]['label'] = $value['settings']['admin_field_label'];
83 $fields_data[$value['attributes']['name']][$sub_fkey] = [
84 'label' => $field_lbl
85 ];
86 }
87 }else if('container' === $value['element']){
88 if(!empty($value['columns']) && is_array($value['columns'])){
89 foreach($value['columns'] as $col_key => $col_value){
90 foreach($col_value['fields'] as $ckey => $cval){
91
92 if(in_array($cval['element'], $excluded_field_types)){
93 continue;
94 }
95
96 $field_type = $cval['attributes']['type'];
97 $field_lbl = !empty($cval['settings']['label'])?$cval['settings']['label']:'Field_'.$cval['attributes']['name'];
98 $field_name = $cval['attributes']['name'];
99 if('input_image' == $cval['element']){
100 $field_type = 'image';
101 }
102
103 if($field_name == 'names') {
104 foreach($cval['fields'] as $field_key => $field_val){
105 $field_type = $field_val['attributes']['type'];
106 $field_name = $field_val['attributes']['name'];
107 $field_lbl = $field_val['settings']['label'];
108
109 $fields_data[$cval['attributes']['name']]['type'] = $field_type;
110 $fields_data[$cval['attributes']['name']]['label'] = $cval['settings']['admin_field_label'];
111 $fields_data[$cval['attributes']['name']][$field_key] = [
112 'label' => $field_lbl
113 ];
114 }
115 }else{
116 $fields_data[$field_name] = [
117 'label' => $field_lbl,
118 'type' => $field_type,
119 ];
120 }
121 }
122 }
123 }
124 }else if('input_image' === $value['element']) {
125 $field_type = 'image';
126 $field_name = $value['attributes']['name'];
127
128 if(!empty($value['settings']['label'])){
129 $field_lbl = $value['settings']['label'];
130 }else if(!empty($value['settings']['admin_field_label'])){
131 $field_lbl = $value['settings']['admin_field_label'];
132 }else{
133 $field_lbl = 'Field_'.$value['attributes']['name'];
134 }
135
136 $fields_data[$field_name] = [
137 'label' => $field_lbl,
138 'type' => $field_type,
139 ];
140 }else {
141 $field_type = !empty($value['attributes']['type'])?$value['attributes']['type']:'text';
142 $field_name = $value['attributes']['name'];
143
144 if(!empty($value['settings']['label'])){
145 $field_lbl = $value['settings']['label'];
146 }else if(!empty($value['settings']['admin_field_label'])){
147 $field_lbl = $value['settings']['admin_field_label'];
148 }else{
149 $field_lbl = 'lbl_'.$value['attributes']['name'];
150 }
151
152 $fields_data[$field_name] = [
153 'label' => $field_lbl,
154 'type' => $field_type,
155 ];
156 }
157 }
158 }
159
160 if(is_array($fields_data) && !empty($fields_data)){
161 foreach($fields_data as $field_key => $field_value){
162
163 $field_name = $field_value['name'];
164 $field_label = $field_value['label'];
165 $field_type = $field_value['type'];
166 if($field_type == 'image'){
167 $return_type = 'image';
168 }else{
169 $return_type = 'text';
170 }
171
172
173 $merge_tags['Fluent Forms'][] = array(
174 'id' => 'fluentforms_' . $form_id . '_' . $field_key,
175 'label' => ucfirst(str_replace('_',' ',$field_label)),
176 'preview_value' => '',
177 'return_type' => $return_type,
178 'value' => function ( $formData ) use ( $field_key ) {
179 $value = isset($formData[$field_key]) ? $formData[$field_key] : '';
180 if(is_array($value)){
181 $value = implode(', ', $value);
182 }
183 return html_entity_decode(sanitize_text_field($value));
184 }
185 );
186 }
187 }
188
189 return $merge_tags;
190 }
191
192 /*
193 * Get recipient fields
194 */
195 public static function get_recipient_fields( $form_id ){
196 $recipient_fields = array();
197 $fields_data = array();
198 $formApi = fluentFormApi('forms')->form($form_id);
199 $form_fields = $formApi->fields();
200 $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');
201
202 if(is_array($form_fields)){
203 foreach($form_fields['fields'] as $key => $value){
204 if(in_array($value['element'], $excluded_field_types)){
205 continue;
206 }
207
208 if('container' === $value['element']){
209 if(!empty($value['columns']) && is_array($value['columns'])){
210 foreach($value['columns'] as $col_key => $col_value){
211 foreach($col_value['fields'] as $ckey => $cval){
212
213 if(in_array($cval['element'], $excluded_field_types)){
214 continue;
215 }
216
217 $field_type = $cval['attributes']['type'];
218 if('tel' == $field_type){
219 $field_lbl = !empty($cval['settings']['label'])?$cval['settings']['label']:'Field_'.$cval['attributes']['name'];
220 $field_name = $cval['attributes']['name'];
221
222 $fields_data[$field_name] = [
223 'label' => $field_lbl,
224 'type' => $field_type,
225 ];
226 }
227 }
228 }
229 }
230 }else {
231 $field_type = $value['attributes']['type'];
232 if('tel' == $field_type){
233 $field_name = $value['attributes']['name'];
234
235 if(!empty($value['settings']['label'])){
236 $field_lbl = $value['settings']['label'];
237 }else if(!empty($value['settings']['admin_field_label'])){
238 $field_lbl = $value['settings']['admin_field_label'];
239 }else{
240 $field_lbl = 'lbl_'.$value['attributes']['name'];
241 }
242
243 $fields_data[$field_name] = [
244 'label' => $field_lbl,
245 'type' => $field_type,
246 ];
247 }
248 }
249 }
250 }
251
252 if(is_array($fields_data) && !empty($fields_data)){
253 foreach($fields_data as $field_key => $field_value){
254 if('tel' != $field_value['type']){
255 continue;
256 }
257
258 $field_name = $field_value['name'];
259 $field_label = $field_value['label'];
260
261 $recipient_fields['Fluent Forms'][] = array(
262 'id' => 'fluentforms_' . $form_id . '_' . $field_key,
263 'label' => ucfirst(str_replace('_',' ',$field_label)),
264 'value' => function ( $formData ) use ( $field_key ) {
265 $value = isset($formData[$field_key]) ? $formData[$field_key] : '';
266 return html_entity_decode(sanitize_text_field($value));
267 }
268 );
269 }
270 }
271
272 return $recipient_fields;
273 }
274 }
275