-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-gravityforms-to-zendesk.php
125 lines (114 loc) · 4.25 KB
/
send-gravityforms-to-zendesk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This code was originally part of the functions file and was used to send entries from gravity forms into zendesk.
* Use this to help getting started with getting gravity form entries to send to a blockchain.
*/
/*
* ZENDESK API
*/
define("ZDAPIKEY", "r5az19PLJmsfoznLRgl8G5cREqxqmknduupwo19M");
define("ZDUSER", "[email protected]");
define("ZDURL", "https://draftbernie.zendesk.com/api/v2");
/*
* Here goes the Gravity Forms Functions
*/
add_action("gform_after_submission_1", "send_contact_to_zendesk1", 10, 2); // Invoke ZENDESK for form #1
add_action("gform_after_submission_3", "send_contact_to_zendesk3", 10, 2); // Invoke ZENDESK for form #1
//add_action("gform_after_submission_1", "ult_cu_disable_post_creation", 20, 2); // Disable entry creation for FROM id #1
/*
* Deletes entry created in WordPress Dashboard
*/
//function ult_cu_disable_post_creation( $entry, $form ) {
// GFAPI::delete_entry( $entry['id'] );
//}
/*
* Prepares and sends data to Zendesk
*/
function send_contact_to_zendesk1($entry,$form){
$create = json_encode(
array(
'ticket' => array(
'subject' => 'Contact Form Entry', // Title of ticket ids of fields you need in subject field ours was type of request - message title
'comment' => array(
"value"=> 'Joining: ' . $entry[4]. ' - Zipcode: ' . $entry["5.5"] . ' - Country: ' . $entry["5.6"] . ' - Skills: ' . $entry[6] . ' - Comment: ' . $entry[3] // content of the ticket
),
'requester' => array(
'name' => $entry[1], // Name of ticket creator
'email' => $entry[2] // email of ticket creator
)
)
)
);
$return = ZD_contact_us_curlWrap("/tickets.json", $create);
}
function send_contact_to_zendesk3($entry,$form){
$interests = "";
if($entry["17.1"]){
$interests .= $entry["17.1"] . ', ';
}
if($entry["17.2"]){
$interests .= $entry["17.2"] . ', ';
}
if($entry["17.3"]){
$interests .= $entry["17.3"] . ', ';
}
if($entry["17.4"]){
$interests .= $entry["17.4"] . ', ';
}
if($entry["17.5"]){
$interests .= $entry["17.5"] . ', ';
}
if($entry["17.6"]){
$interests .= $entry["17.6"] . ', ';
}
$social = "";
if($entry[12]){
$social .= ' - Facebook: ' . $entry[12] . ', ';
}
if($entry[13]){
$social .= ' - Twitter: ' . $entry[13] . ', ';
}
if($entry[14]){
$social .= ' - Instagram: ' . $entry[14] . ', ';
}
if($entry[15]){
$social .= ' - Reddit: ' . $entry[15] . ', ';
}
$create = json_encode(
array(
'ticket' => array(
'subject' => 'Volunteer Form Entry', // Title of ticket ids of fields you need in subject field ours was type of request - message title
'comment' => array(
"value"=> 'City: ' . $entry[4] . ' - Zipcode: ' . $entry[7] . ' - Phone: ' . $entry[5] . ' - Presidential Primary Involvement: ' . $entry[9] . ' - Interests: ' . $interests . $entry[11] . $social . ' - Comments: ' . $entry[16] // content of the ticket
),
'requester' => array(
'name' => $entry[1] . ' ' . $entry[2], // Name of ticket creator
'email' => $entry[6] // email of ticket creator
)
)
)
);
$return = ZD_contact_us_curlWrap("/tickets.json", $create);
}
/*
* Zendesk post function
* TODO : use wp_remote_post
*/
function ZD_contact_us_curlWrap($url, $json){
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($output);
return $decoded;
}
?>