-
-
Save leoborlot/2ae51b8045fd5a2528f81dc1fa96a13a to your computer and use it in GitHub Desktop.
add-wp-user-to-mautic.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * este código peguei aqui: https://medium.com/@jan_linhart/the-simplest-way-how-to-submit-a-form-data-to-mautic-1454d3afd005#.k5gmcrvjf | |
| * Push data to a Mautic form | |
| * | |
| * Basicamente precisa ter um form do mautic com o campo email e este campo precisa se chamar "email"e | |
| * depois alterar as linhas 19 e 21 com os seus dados | |
| * e colar todo esse conteúdo dentro do functions do seu wordpress. só. | |
| * | |
| * @param array $data The data submitted by your form | |
| * @param integer $formId Mautic Form ID | |
| * @param string $ip IP address of the lead | |
| * @return boolean | |
| */ | |
| function pushMauticForm($data, $ip = null) | |
| { | |
| // Aqui você coloca a url do seu mautic | |
| $mautic_url = 'https://marketing.orangeweb.com.br'; | |
| // Aqui você coloca o ID do seu form | |
| $formId = 1; | |
| // Get IP from $_SERVER | |
| if (!$ip) { | |
| $ipHolders = array( | |
| 'HTTP_CLIENT_IP', | |
| 'HTTP_X_FORWARDED_FOR', | |
| 'HTTP_X_FORWARDED', | |
| 'HTTP_X_CLUSTER_CLIENT_IP', | |
| 'HTTP_FORWARDED_FOR', | |
| 'HTTP_FORWARDED', | |
| 'REMOTE_ADDR' | |
| ); | |
| foreach ($ipHolders as $key) { | |
| if (!empty($_SERVER[$key])) { | |
| $ip = $_SERVER[$key]; | |
| if (strpos($ip, ',') !== false) { | |
| // Multiple IPs are present so use the last IP which should be the most reliable IP that last connected to the proxy | |
| $ips = explode(',', $ip); | |
| array_walk($ips, create_function('&$val', '$val = trim($val);')); | |
| $ip = end($ips); | |
| } | |
| $ip = trim($ip); | |
| break; | |
| } | |
| } | |
| } | |
| $data['formId'] = $formId; | |
| // return has to be part of the form data array | |
| if (!isset($data['return'])) { | |
| $data['return'] = $mautic_url; | |
| } | |
| $data = array('mauticform' => $data); | |
| // Change [path-to-mautic] to URL where your Mautic is | |
| $formUrl = $mautic_url . '/form/submit?formId=' . $formId; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $formUrl); | |
| curl_setopt($ch, CURLOPT_POST, 1); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Forwarded-For: $ip")); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| return $response; | |
| } | |
| // registrando o hook | |
| add_action( 'user_register', 'action_after_user_register', 10, 1 ); | |
| // executa apos o registro do usuario no site | |
| function action_after_user_register( $user_id ) { | |
| $author= get_user_by('id', $user_id); | |
| pushMauticForm(array('email' => $author->user_email), $ip = null); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment