2015-07-10 52 views
1

我使用插件mailjet-for-wordpress。wordpress插件mailjet-for-wordpress無法在前端插入聯繫人屬性字段到簡報表格

我想要什麼

要用戶輸入thier標稱,prenom和電子郵件在前端是這樣的:http://gyazo.com/b58675c671584f8edc6ab6d703370ba9

我的問題

現場我只是添加像標稱, prenom它不會顯示在我的管理頁面中,當用戶使用subcribe時,與電子郵件字段相同:http://gyazo.com/9b72fdc03d22732cf21ddac9f70b2c33

我曾嘗試過

我試圖在mailjet中創建聯繫屬性字段,如nom,prenom。而且我還嘗試修改小部件「下載到我們的通訊」我在通訊表單中添加更多字段。我有修改如下代碼:

文件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="' . __('[email protected]', '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(); 
} 

我試圖尋找和測試這樣的幾天但仍然不能得到結果。我是新的插件mailjet-for-word插件, 有誰知道幫我找到解決方案請,

先進的感謝,

回答

0

我們想建議2個額外的API調用。

  1. 獲得接觸ID GET https://api.mailjet.com/v3/REST/contact/[email protected] 您會收到類似
 
    "Count": 1, 
    "Data": [ { 
     "CreatedAt": "2014-12-03T12:30:10Z", 
     "DeliveredCount": 79, 
     "Email": "[email protected]", 
     "ID": 5, 
     "IsOptInPending": false, 
     "IsSpamComplaining": false, 
     "LastActivityAt": "2015-04-07T08:35:51Z", 
     "LastUpdateAt": "2014-12-03T12:30:10Z", 
     "Name": "", 
     "UnsubscribedAt": "", 
     "UnsubscribedBy": "" 
    }], 
    "Total": 1 
響應
  • 然後通過使用ID從以前的電話,你應該更新聯繫人屬性(在此情況下的ID = 5)
  • PUT https://api.mailjet.com/v3/REST/contactdata/5

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

    響應將包含具有更新數據的相同數據對象。

    要將這兩個API請求集成到WP插件中,您應該添加並創建更多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這裏將是$結果-數據[0]> ID

    對於第二個電話,請使用該示例進行集成。

    相關問題