0

我是 PHP 和 wordpress(可怕的开瓶器)的新手,我正在尝试向我使用 Wordpress 的 LearnDash 插件构建的电子学习网站添加一些功能。

我跟踪用户进度的方法之一是使用 ActiveCampaign。站点跟踪已安装并且运行良好,但我试图在用户完成课程时让事件登录到 AC。有一个可用的 LearnDash 钩子 ( https://www.learndash.com/support/docs/developers/hooks-and-filters/ ),实际的事件代码可从 Active Campaign 跟踪页面获得。

我最终得到了以下代码:


//learndash hook:
add_action("learndash_course_completed", sendEmail,5,1);

//defining user's email to use in tracking event code:
function sendEmail(){
    $current_user = wp_get_current_user();
    $userEmail = $user->user_email;

//Event Tracking code as per the Active Campaign Page - Account info omitted

    $curl = curl_init();
       curl_setopt($curl, CURLOPT_URL, "https://trackcmp.net/event");
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POST, true);
       curl_setopt($curl, CURLOPT_POSTFIELDS, array(
       "actid" => "ACCOUNT ID NUMBER",
       "key" => "TRACKING KEY NUMBER",
       "event" => "EVENT NAME",
       "eventdata" => "User Has Completed the course",
       "visit" => json_encode(array(
               // If you have an email address, assign it here.
               "email" => $userEmail,
           )),
       ));

       $result = curl_exec($curl);
       if ($result !== false) {
           $result = json_decode($result);
           if ($result->success) {
               echo 'Success! ';
           } else {
               echo 'Error! ';
           }

           echo $result->message;
       } else {
           echo 'cURL failed to run: ', curl_error($curl);
}
};

当用户完成课程并且我不确定我做错了什么时,它不会触发。可能是非常明显的事情。有什么想法吗?

谢谢!

4

1 回答 1

0

我发现了问题:我调用了$user变量,而它实际上被定义为$current-user.

改变它解决了这个问题。

于 2019-10-24T10:49:48.983 回答