wordpress 插件 mailjet-for-wordpress 无法将联系人属性字段插入前端的时事通讯表单

wordpress plugin mailjet-for-wordpress can not insert contact properties field to newsletter form in frontend

我使用插件 mailjet-for-wordpress。

我想要的

希望用户像这样在前端输入他们的姓名、姓名和电子邮件:http://gyazo.com/b58675c671584f8edc6ab6d703370ba9

我的问题

对于我只是添加的字段,如 nom,prenom,当用户订阅时,它不会像电子邮件字段一样显示在我的管理页面中:http://gyazo.com/9b72fdc03d22732cf21ddac9f70b2c33

我试过的

我尝试在 mailjet 中创建联系属性字段,例如 nom、prenom。而且我还尝试修改小部件 "Subscript to our newsletter" 我在时事通讯表单中添加了更多字段。我修改代码如下:

文件 mailjet-widget.php

    // WIDGET CODE GOES HERE
    echo '
    <form class="subscribe-form">
        //add field nom
        <input type="text" name="nom" placeholder="' . __('Nom', 'wp-mailjet') . '" class="username">

        //add field prenom
        <input type="text" name="prenom" placeholder="' . __('Prenom', 'wp-mailjet') . '" class="username">
        //email it is original field in default newsletter mailjet form
        <input id="email" name="email" value="" type="email" placeholder="' . __('your@email.com', 'wp-mailjet') . '" />

        <input name="action" type="hidden" value="mailjet_subscribe_ajax_hook" />
        <input name="list_id" type="hidden" value="' . $list_id . '" />
        <input name="submit" type="submit" class="mailjet-subscribe" value="' . __($button_text) . '">
    </form>
    <div class="response">
    </div>';

还有这个函数mailjet_subscribe_from_widget()

public function mailjet_subscribe_from_widget()
{
    // Get some variables - email, list_id, etc.
    $email = $_POST['email'];
    $list_id = $_POST['list_id'];
    //field add
    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];

    // Add the contact to the contact list
    $result = $this->api->addContact(array(
        'Email'     => $email,
        'Nom'       => $nom,
        'Prenom'    => $prenom,
        'ListID'    => $list_id
    ));

    // Check what is the response and display proper message
    if(isset($result->Status)) {
        if($result->Status == 'DUPLICATE'){
            echo '<p class="error">';
            echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet'), $email);
            echo '</p>';
            die();
        }
        else if($result->Status == 'ERROR'){
            echo '<p class="error">';
            echo sprintf(__("Sorry %s we couldn't subscribe at this time", 'wp-mailjet'), $email);
            echo '</p>';
            die();
        }           
    }

    // Adding was successful
    echo '<p class="success">';
    echo sprintf(__("Thanks for subscribing with %s", 'wp-mailjet'), $email);
    echo '</p>';
    die();
}

我试了几天这样搜索和测试,但仍然无法获得 result.I 新插件 mailjet-for-wordpress 插件, 有谁知道请帮我找到解决方案,

在此先致谢,

我们建议再进行 2 次 API 调用。

  1. 获取联系人 ID 获取 https://api.mailjet.com/v3/REST/contact/user@email.com 您应该会收到类似于
  2. 的回复
    "Count": 1,
    "Data": [ {
        "CreatedAt": "2014-12-03T12:30:10Z",
        "DeliveredCount": 79,
        "Email": "user@email.com",
        "ID": 5,
        "IsOptInPending": false,
        "IsSpamComplaining": false,
        "LastActivityAt": "2015-04-07T08:35:51Z",
        "LastUpdateAt": "2014-12-03T12:30:10Z",
        "Name": "",
        "UnsubscribedAt": "",
        "UnsubscribedBy": "" 
    }],
    "Total": 1
  1. 然后通过使用上次调用的 ID,您应该更新联系人属性(在本例中为 ID=5)

放置https://api.mailjet.com/v3/REST/contactdata/5

        {
    "Data": [ {
    "Name": "nom",
    "Value": "Bond" 
    }, {
    "Name": "prenom",
    "Value": "James Bond" 
    }

响应将包含具有更新数据的相同数据对象。

要在 WP 插件中集成这两个 API 请求,您应该添加和创建更多 PHP 方法。

第一个 API 调用的示例:

In mailjet-api-strategy.php
in class WP_Mailjet_Api add
public function     findContactByEmail($email) 

    {
      return $this->context->findContactByEmail($params);
    }

(assuming you are v3 user) in class WP_Mailjet_Api_Strategy_V3 add
public function findContactByEmail($email) 

        {
      return $this->{'contact/'.$email}(array(
        'method' => 'GET',
      ))
    }

在 mailjet_subscribe_widget() 中获取联系人 ID

 $result = $this->api->findContactByEmail(array(
'Email' => $email,

这里的 ID 在 $result-Data[0]>ID

第二次调用,请使用示例进行集成。