我一直在寻找一种解决方案,以便在提交表单后将WP用户数据导出到另一个应用程序。有一篇文章是关于如何做到这一点的,但我太笨了,无法让它发挥作用,我请求有人帮助我完成脚本。
基本上,这是一个add\\u操作挂钩,在提交表单时触发。提交时,脚本将创建一个用户数据数组,并将其发送到存在表单的应用程序以接收数据。。
我想弄清楚的是,如何实际构建阵列?我以前使用过do\\u动作挂钩,所以我在那里很好,脚本的通信端已经完全形成。因此,现在剩下的就是插入数组。
我对这项工作非常感兴趣,并渴望了解需要做什么。
可以找到脚本本身here
<?php
/**
* Push data to a Mautic form
*
* @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, $formId, $ip = null)
{
// 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\'] = \'http://where-to-redirect.com\';
}
$data = array(\'mauticform\' => $data);
// Change [path-to-mautic] to URL where your Mautic is
$formUrl = \'http://[path-to-mautic]/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;
}
现在作者说:
pushMauticForm($_REQUEST, 3);
// $_REQUEST can look like:
// array(\'email\' => \'[email protected]\', \'message\' => \'Test message\')
然后,ID=3的Mautic表单必须具有名为email和message的字段`
因此,我尝试(但不起作用)的是:
这是表单信息:
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}
$user = get_user_by( \'id\', get_current_user_id() );
$firstname = ! empty( $_POST[\'vendor-owner-firstname\'] ) ? sanitize_text_field( $_POST[\'vendor-owner-firstname\'] ) : \'\';
$lastname = ! empty( $_POST[\'vendor-owner-lastname\'] ) ? sanitize_text_field( $_POST[\'vendor-owner-lastname\'] ) : \'\';
<?php
/**
* Push data to a Mautic form
*
* @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
*/
//do_action hook passes 2 arguments $vendorId, $userId
add_action(\'yith_after_form_submitted\', "pushMauticForm, 2, 10)";
function pushMauticForm($vendorId, $userId, $data, $formId, $ip = null)
{
//set Mautic form ID
$formId = \'3\';
//get array of form data;
//example: match mautic label (left) with form label ($_REQUEST[\'vendor-owner-firstname\']
global $data;
$first_name = $data->($_REQUEST[\'vendor-owner-firstname\']);
$last_name = $data->($_REQUEST[\'vendor-owner-lastname\']);
$email = $data->($_REQUEST[\'vendor-email\']);
$some_other_data = $data->($REQUEST[\'more_data\']);