PluginProbe
WANotifier for Forms and Actions / 2.4.2
WANotifier for Forms and Actions v2.4.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 / integrations / class-notifier-ninjaforms.php

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

123 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ninja Forms notifications
4 *
5 * @package Wa_Notifier
6 */
7 class Notifier_NinjaForms {
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 $forms = Ninja_Forms()->form()->get_forms();
22
23 if(is_array($forms)){
24 foreach($forms as $form){
25 $form_id = $form->get_id();
26 $title = $form->get_setting( 'form_title' );
27 $trigger_id = 'ninjaforms_' . $form_id;
28
29 $triggers[] = array(
30 'id' => $trigger_id,
31 'label' => 'Form "' . $title . '" is submitted',
32 'description' => 'Trigger notification when <b>'.$title.'</b> form is submitted.',
33 'merge_tags' => self::get_merge_tags($form_id),
34 'recipient_fields' => self::get_recipient_fields($form_id),
35 'action' => array(
36 'hook' => 'ninja_forms_after_submission',
37 'callback' => function ( $form_data ) use ( $trigger_id, $form_id ) {
38 if( $form_id != $form_data['form_id'] ) {
39 return;
40 }
41
42 Notifier_Notification_Triggers::send_trigger_request( $trigger_id, $form_data );
43 },
44 )
45 );
46 }
47 }
48
49 $existing_triggers['Ninja Forms'] = $triggers;
50 return $existing_triggers;
51 }
52
53 /**
54 * Get merge tags for the current form
55 */
56 public static function get_merge_tags( $form_id ) {
57
58 $merge_tags = Notifier_Notification_Merge_Tags::get_merge_tags();
59 $ninjaforms_fields = Ninja_Forms()->form( $form_id )->get_fields();
60
61 $excluded_field_types = array('submit', 'recaptcha', 'confirm', 'spam', 'hr', 'repeater', 'save');
62 $form_fields = $ninjaforms_fields;
63
64 if(is_array($form_fields)){
65 foreach($form_fields as $field){
66
67 if(in_array($field->get_setting('type'), $excluded_field_types)){
68 continue;
69 }
70
71 $field_name = $field->get_setting('label');
72 $field_id = $field->get_id();
73 $return_type = 'text';
74
75 $merge_tags['Ninja Forms'][] = array(
76 'id' => 'ninjaforms_' . $form_id . '_' . $field_id,
77 'label' => $field_name,
78 'preview_value' => '',
79 'return_type' => $return_type,
80 'value' => function ( $form_data ) use ( $field_id ) {
81 $value = isset($form_data['fields'][$field_id][ 'value' ]) ? $form_data['fields'][$field_id][ 'value' ] : '';
82 if(is_array($value)){
83 $value = implode(', ', $value);
84 }
85 return html_entity_decode(sanitize_text_field($value));
86 }
87 );
88 }
89 }
90 return $merge_tags;
91 }
92
93 /*
94 * Get recipient fields
95 */
96 public static function get_recipient_fields( $form_id ){
97 $ninjaforms_fields = Ninja_Forms()->form( $form_id )->get_fields();
98 $form_fields = $ninjaforms_fields;
99 $recipient_fields = array();
100
101 if(is_array($form_fields)){
102 foreach($form_fields as $field){
103 if('phone' != $field->get_setting('type')){
104 continue;
105 }
106
107 $field_name = $field->get_setting('label');
108 $field_id = $field->get_id();
109
110 $recipient_fields['Ninja Forms'][] = array(
111 'id' => 'ninjaforms_' . $form_id . '_' . $field_id,
112 'label' => $field_name,
113 'value' => function ( $form_data ) use ( $field_id ) {
114 $value = isset($form_data['fields'][$field_id][ 'value' ]) ? $form_data['fields'][$field_id][ 'value' ] : '';
115 return html_entity_decode(sanitize_text_field($value));
116 }
117 );
118 }
119 }
120 return $recipient_fields;
121 }
122 }
123