我正在尝试使用重力形式的after_submission挂钩来运行发布到API的curl脚本。
有一个输入字段可以捕获在用户提交表单后需要发布的site_name。该表单还将付款信息传递给Stripe,目前正在使用。我尝试将以下代码添加到function.php,但该网站尚未发布。
add_action( 'gform_after_submission_5', ‘publish_site’, 10, 2 );
function publish_site($entry, $form)
{
$site_name = $entry[“11”];
$ch = curl_init();
//Set cURL parameters
curl_setopt($ch, CURLOPT_URL, 'https://api.site.com/api/sites/publish/{$site_name}?test=true');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'APIusername:APIpassword');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
//Perform cURL call and set $output as returned data, if any is returned
$output = curl_exec($ch);
curl_close($ch);
}