Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // START OF CODE
- // CF7 – Case Evaluation/General Contact Form Webhook
- add_action( ‘wpcf7_before_send_mail’, ‘my_conversion’ );
- function my_conversion( $contact_form ) {
- $submission = WPCF7_Submission::get_instance();
- $form_id = $contact_form->posted_data[‘_wpcf7’];
- // Get the post data and other post meta values
- if (form_id == 11021) {
- $posted_data = $submission->get_posted_data();
- $remote_ip = $submission->get_meta( ‘remote_ip’ );
- $url = $submission->get_meta( ‘url’ );
- $timestamp = gmdate(“m/d/Y H:i:s”, $submission->get_meta( ‘timestamp’ ));
- $title = wpcf7_special_mail_tag( ”, ‘_post_title’, ” );
- // Split the first and last names
- if ($posted_data[“fullname”]){
- $name = trim($posted_data[“fullname”]);
- $last_name = (strpos($name, ‘ ‘) === false) ? ” : preg_replace(‘#.*\s([\w-]*)$#’, ‘$1’, $name);
- $first_name = trim( preg_replace(‘#’.$last_name.’#’, ”, $name ) );
- if ($last_name == NULL ){
- $last_name = “(none)”;
- }
- }
- // Encode the data in JSON format
- $data = json_encode(array(
- “email” => “{$posted_data[“email”]}”,
- “first-name” => “$first_name”,
- “last-name” => “$last_name”,
- “fullname” => “{$posted_data[“fullname”]}”,
- “telephone” => “{$posted_data[“telephone”]}”,
- “General Message” => “{$posted_data[“gen-message”]}”,
- “Form ID” => “$form_id”
- ));
- // Hit the webhook, deliver the payload
- $ch = curl_init (“https://hooks.zapier.com/hooks/catch/HOOK”); // Webhook to trigger delivery to admin/marketing depts
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($ch);
- curl_close($ch);
- return;
- } elseif ($form_id==10754) {
- // Converting selection fields into strings
- $casetypes = implode(“, “, $posted_data[“radio-casetypes”]);
- $othercases = implode(“, “, $posted_data[“checkbox-othercases”]);
- $photos = implode(“, “, $posted_data[“photos”]);
- $requestcontact = implode(“, “, $posted_data[“radio-requestcontact”]);
- // Encode the data in JSON format
- $data = json_encode(array(
- “email” => “{$posted_data[“email”]}”,
- “first-name” => “$first_name”,
- “last-name” => “$last_name”,
- “fullname” => “{$posted_data[“fullname”]}”,
- “telephone” => “{$posted_data[“telephone”]}”,
- “casetype” => “$casetypes”,
- “othercases” => “$othercases”,
- “incidentDateAuto” => “{$posted_data[“incident-date-auto”]}”,
- “incidentDatePrem” => “{$posted_data[“incident-date-prem”]}”,
- “incidentDateNeg” => “{$posted_data[“incident-date-neg”]}”,
- “autoInsurancePlaintiff” => “{$posted_data[“auto-insurance”]}”,
- “autoInsuranceDef” => “{$posted_data[“def-auto-insurance”]}”,
- “injuryDescAuto” => “{$posted_data[“descr-injury-auto”]}”,
- “injuryDescPrem” => “{$posted_data[“descr-injury-prem”]}”,
- “injuryDescNursing” => “{$posted_data[“descr-injury-nursing”]}”,
- “whatHappenedAuto” => “{$posted_data[“what-hap-auto”]}”,
- “whatHappenedPrem” => “{$posted_data[“what-hap-prem”]}”,
- “whatHappenedNursing” => “{$posted_data[“what-hap-nursing”]}”,
- “whatHappenedOtherDeath” => “{$posted_data[“what-hap-other-death”]}”,
- “whatHappenedOtherSex” => “{$posted_data[“what-hap-other-sex”]}”,
- “whatHappenedOtherAED” => “{$posted_data[“what-hap-other-aed”]}”,
- “whatHappenedOtherMed” => “{$posted_data[“what-hap-other-med”]}”,
- “whatHappenedOther” => “{$posted_data[“what-hap-other”]}”,
- “locationPrem” => “{$posted_data[“location-prem”]}”,
- “locationNursing” => “{$posted_data[“location-nursing”]}”,
- “photos” => “$photos”,
- “requestContact” => “$requestcontact”,
- “id” => “{$posted_data[“submit_time”]}”,
- “Submitted” => “$timestamp”,
- “URL” => “$url”,
- “From Referer” => “{$posted_data[“referer-page”]}”,
- “From IP” => “$remote_ip”,
- “Page Title” => “$title”,
- “Form ID” => “$form_id”
- ));
- // Hit the webhook, deliver the payload
- $ch1 = curl_init(“https://hooks.zapier.com/hooks/catch/WEBHOOK1”); // Webhook to trigger lead form processing
- $ch2 = curl_init (“https://hooks.zapier.com/hooks/catch/WEBHOOK2”); // Webhook to trigger lead notices to intake
- $ch3 = curl_init (“https://hooks.zapier.com/hooks/catch/WEBHOOK3”); // Webhook to initiate contact with lead
- curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, “POST”);
- curl_setopt($ch1, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch1, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
- curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
- curl_setopt($ch1, CURLOPT_TIMEOUT, 5); //Optional timeout value
- curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, “POST”);
- curl_setopt($ch2, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch2, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
- curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
- curl_setopt($ch2, CURLOPT_TIMEOUT, 5); //Optional timeout value
- curl_setopt($ch3, CURLOPT_CUSTOMREQUEST, “POST”);
- curl_setopt($ch3, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch3, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
- curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
- curl_setopt($ch3, CURLOPT_TIMEOUT, 5); //Optional timeout value
- $mh = curl_multi_init();
- curl_multi_add_handle($mh, $ch1);
- curl_multi_add_handle($mh, $ch2);
- curl_multi_add_handle($mh, $ch3);
- $running = null;
- do {
- curl_multi_exec($mh, $running);
- } while ($running);
- $response_1 = curl_multi_getcontent($ch_1);
- $response_2 = curl_multi_getcontent($ch_2);
- $response_2 = curl_multi_getcontent($ch_3);
- echo “$response_1 $response_2 $response_3”;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement