更新:
我用另一个钩子得到了这个
user_register. 看起来像是
wpmu_activate_user从未触发。
I would still like to have this happen after the user verifies and sets a password though. Can anyone help?
Current Code:
function xxx_whmcs_signup($user_id) {
//Get User Fields
$user_info2 = get_userdata($user_id);
$id = $user_info2->ID;
//Get Custom Fields
$first_name = get_field(\'first_name_c\', \'user_\'. $id );
$last_name = get_field(\'last_name_c\', \'user_\'. $id );
$address1 = get_field(\'address_1\', \'user_\'. $id );
$city = get_field(\'city\', \'user_\'. $id );
$state = get_field(\'state\', \'user_\'. $id );
$postcode = get_field(\'postcode\', \'user_\'. $id );
$country = get_field(\'country\', \'user_\'. $id );
$phonenum = get_field(\'phone_number\', \'user_\'. $id );
$email = $user_info2->user_email;
$password = $user_info2->user_pass;
// Set WHMCS API Details
$whmcsUrl = "xxx";
$apiusername = "xxx";
$apipassword = "xxx";
//Return Fields
$postfields = array(
\'username\' => $apiusername, //WHMCS Username
\'password\' => $apipassword, //WHMCS Password
\'action\' => \'AddClient\', //WHMCS Action
\'firstname\' => $first_name,
\'lastname\' => $last_name,
\'password2\' => $password,
\'email\' => $email,
\'address1\' => $address1,
\'city\' => $city,
\'state\' => $state,
\'postcode\' => $postcode,
\'country\' => $country,
\'phonenumber\' => $phonenum,
\'responsetype\' => \'json\'
);
// Call the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . \'includes/api.php\');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
$response = curl_exec($ch);
if (curl_error($ch)) {
die(\'Unable to connect: \' . curl_errno($ch) . \' - \' . curl_error($ch));
}
curl_close($ch);
// Decode response
$jsonData = json_decode($response, true);
// Dump array structure for inspection
var_dump($jsonData);
$file = fopen("wp-content/plugins/integrations/curloutput.txt", \'w+\');
fwrite($file, $response);
fclose($file);
}
add_action(\'user_register\',"xxx_whmcs_signup",10,1);
原始帖子:我目前正在尝试获取Wordpress注册过程中填充的字段,并将它们发布到另一个API。
我需要掌握的字段包括:
当我创建原始代码时,如果用户已经登录并转到特定页面,我会设法使其正常工作,但在注册过程中,我似乎无法让代码正常工作(可能必须在激活后进行,因为设置密码时就是这样)。
整个代码当前为:
pruned
由于这些字段位于高级自定义字段中,我还尝试了:
pruned
当脚本从页面上的短代码运行时,这一点非常有效,但由于用户在注册过程中没有登录,当然会遇到额外的障碍。我假设这取决于我可以通过钩子传递给函数的信息。
我不完全理解如何将变量传递给函数,也不完全理解如何返回$meta的输出,以便查看正在使用的内容,因此这可能是一项非常简单的任务(祈祷成功)。也有可能我没有使用正确/最好的挂钩?
提前感谢!
最合适的回答,由SO网友:Joseph Berry 整理而成
我可以使用user\\u register挂钩修复此问题。令人恼火的是,我找不到一个wordpress挂钩,它在用户单击激活链接并设置密码后触发,所以我认为它不存在。
wpmu\\u activate\\u user仅适用于多站点安装,这是最令人失望的。
<?php function xxx($user_id) {
//Get User Fields
$user_data = get_userdata($user_id);
$id = $user_data -> ID;
$password = $user_data -> user_pass;
//Get Custom Fields
$first_name = get_field(\'first_name_c\', \'user_\'. $id );
$last_name = get_field(\'last_name_c\', \'user_\'. $id );
$address1 = get_field(\'address_1\', \'user_\'. $id );
$city = get_field(\'city\', \'user_\'. $id );
$state = get_field(\'state\', \'user_\'. $id );
$postcode = get_field(\'postcode\', \'user_\'. $id );
$country = get_field(\'country\', \'user_\'. $id );
$phonenum = get_field(\'phone_number\', \'user_\'. $id );
$email = $user_data -> user_email;
<pruned rest of code>
}
add_action(\'user_register\',"xxx",10,1);
get\\u field()来自高级自定义字段插件。