Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.24 KB | None | 0 0
  1. // START OF CODE
  2. // CF7 – Case Evaluation/General Contact Form Webhook
  3. add_action( ‘wpcf7_before_send_mail’, ‘my_conversion’ );
  4. function my_conversion( $contact_form ) {
  5.     $submission = WPCF7_Submission::get_instance();
  6.     $form_id = $contact_form->posted_data[‘_wpcf7’];
  7.  
  8. // Get the post data and other post meta values
  9.     if (form_id == 11021) {
  10.         $posted_data = $submission->get_posted_data();
  11.         $remote_ip = $submission->get_meta( ‘remote_ip’ );
  12.         $url = $submission->get_meta( ‘url’ );
  13.         $timestamp = gmdate(“m/d/Y H:i:s”, $submission->get_meta( ‘timestamp’ ));
  14.         $title = wpcf7_special_mail_tag(, ‘_post_title’,);
  15.  
  16. // Split the first and last names
  17.         if ($posted_data[“fullname”]){
  18.             $name = trim($posted_data[“fullname”]);
  19. $last_name = (strpos($name, ‘ ‘) === false) ? ” : preg_replace(#.*\s([\w-]*)$#’, ‘$1’, $name);
  20. $first_name = trim( preg_replace(#’.$last_name.’#’, ”, $name ) );
  21.     if ($last_name == NULL ){
  22.         $last_name =(none);
  23.     }
  24. }
  25.  
  26. // Encode the data in JSON format
  27. $data = json_encode(array(
  28.     “email” =>{$posted_data[“email”]},
  29.     “first-name” =>$first_name”,
  30.     “last-name” =>$last_name”,
  31.     “fullname” =>{$posted_data[“fullname”]},
  32.     “telephone” =>{$posted_data[“telephone”]},
  33.     “General Message” =>{$posted_data[“gen-message”]},
  34.     “Form ID” =>$form_id”
  35. ));
  36.  
  37. // Hit the webhook, deliver the payload
  38. $ch = curl_init (“https://hooks.zapier.com/hooks/catch/HOOK”); // Webhook to trigger delivery to admin/marketing depts
  39.     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
  40.     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  41.     curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
  42.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  43.     $result = curl_exec($ch);
  44.     curl_close($ch);
  45.     return;
  46.  
  47. } elseif ($form_id==10754) {
  48.  
  49. // Converting selection fields into strings
  50.     $casetypes = implode(,, $posted_data[“radio-casetypes”]);
  51.     $othercases = implode(,, $posted_data[“checkbox-othercases”]);
  52.     $photos = implode(,, $posted_data[“photos”]);
  53.     $requestcontact = implode(,, $posted_data[“radio-requestcontact”]);
  54.  
  55. // Encode the data in JSON format
  56.     $data = json_encode(array(
  57.         “email” =>{$posted_data[“email”]},
  58.         “first-name” =>$first_name”,
  59.         “last-name” =>$last_name”,
  60.         “fullname” =>{$posted_data[“fullname”]},
  61.         “telephone” =>{$posted_data[“telephone”]},
  62.         “casetype” =>$casetypes”,
  63.         “othercases” =>$othercases”,
  64.         “incidentDateAuto” =>{$posted_data[“incident-date-auto”]},
  65.         “incidentDatePrem” =>{$posted_data[“incident-date-prem”]},
  66.         “incidentDateNeg” =>{$posted_data[“incident-date-neg”]},
  67.         “autoInsurancePlaintiff” =>{$posted_data[“auto-insurance”]},
  68.         “autoInsuranceDef” =>{$posted_data[“def-auto-insurance”]},
  69.         “injuryDescAuto” =>{$posted_data[“descr-injury-auto”]},
  70.         “injuryDescPrem” =>{$posted_data[“descr-injury-prem”]},
  71.         “injuryDescNursing” =>{$posted_data[“descr-injury-nursing”]},
  72.         “whatHappenedAuto” =>{$posted_data[“what-hap-auto”]},
  73.         “whatHappenedPrem” =>{$posted_data[“what-hap-prem”]},
  74.         “whatHappenedNursing” =>{$posted_data[“what-hap-nursing”]},
  75.         “whatHappenedOtherDeath” =>{$posted_data[“what-hap-other-death”]},
  76.         “whatHappenedOtherSex” =>{$posted_data[“what-hap-other-sex”]},
  77.         “whatHappenedOtherAED” =>{$posted_data[“what-hap-other-aed”]},
  78.         “whatHappenedOtherMed” =>{$posted_data[“what-hap-other-med”]},
  79.         “whatHappenedOther” =>{$posted_data[“what-hap-other”]},
  80.         “locationPrem” =>{$posted_data[“location-prem”]},
  81.         “locationNursing” =>{$posted_data[“location-nursing”]},
  82.         “photos” =>$photos”,
  83.         “requestContact” =>$requestcontact”,
  84.         “id” =>{$posted_data[“submit_time”]},
  85.         “Submitted” =>$timestamp”,
  86.         “URL” =>$url”,
  87.         “From Referer” =>{$posted_data[“referer-page”]},
  88.         “From IP” =>$remote_ip”,
  89.         “Page Title” =>$title”,
  90.         “Form ID” =>$form_id”
  91.     ));
  92.  
  93. // Hit the webhook, deliver the payload
  94. $ch1 = curl_init(“https://hooks.zapier.com/hooks/catch/WEBHOOK1”); // Webhook to trigger lead form processing
  95. $ch2 = curl_init (“https://hooks.zapier.com/hooks/catch/WEBHOOK2”); // Webhook to trigger lead notices to intake
  96. $ch3 = curl_init (“https://hooks.zapier.com/hooks/catch/WEBHOOK3”); // Webhook to initiate contact with lead
  97.     curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, “POST”);
  98.     curl_setopt($ch1, CURLOPT_POSTFIELDS, $data);
  99.     curl_setopt($ch1, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
  100.     curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
  101. curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
  102. curl_setopt($ch1, CURLOPT_TIMEOUT, 5); //Optional timeout value
  103. curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, “POST”);
  104. curl_setopt($ch2, CURLOPT_POSTFIELDS, $data);
  105. curl_setopt($ch2, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
  106. curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
  107. curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
  108. curl_setopt($ch2, CURLOPT_TIMEOUT, 5); //Optional timeout value
  109. curl_setopt($ch3, CURLOPT_CUSTOMREQUEST, “POST”);
  110. curl_setopt($ch3, CURLOPT_POSTFIELDS, $data);
  111. curl_setopt($ch3, CURLOPT_HTTPHEADER, array(‘Content-Type:application/json’));
  112. curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
  113. curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT , 5); //Optional timeout value
  114. curl_setopt($ch3, CURLOPT_TIMEOUT, 5); //Optional timeout value
  115.  
  116. $mh = curl_multi_init();
  117. curl_multi_add_handle($mh, $ch1);
  118. curl_multi_add_handle($mh, $ch2);
  119. curl_multi_add_handle($mh, $ch3);
  120.  
  121. $running = null;
  122. do {
  123.     curl_multi_exec($mh, $running);
  124. } while ($running);
  125.  
  126. $response_1 = curl_multi_getcontent($ch_1);
  127. $response_2 = curl_multi_getcontent($ch_2);
  128. $response_2 = curl_multi_getcontent($ch_3);
  129. echo$response_1 $response_2 $response_3”;
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement