コード例 #1
0
 /**
  * use the field config mapping to lookup a meta (ex. if MERGE1 maps to
  * user_registered, look that up)
  *
  * @param string $field the field name. this is always uppercase
  * @param string $list_id id of the email list to use
  * @return the field mapping config if set, or NULL if not
  */
 public function get_field_config($field, $list_id)
 {
     $config = go_mailchimp()->config();
     $field_config = NULL;
     if (isset($config['lists'][$list_id]['field_map'][strtoupper($field)])) {
         $field_config = $config['lists'][$list_id]['field_map'][strtoupper($field)];
     }
     return $field_config;
 }
コード例 #2
0
 /**
  * test the api functions
  */
 public function test_api()
 {
     $list_id = 'a3e91a3095';
     // id for the Test General Users list
     $email = '*****@*****.**';
     $new_email = '*****@*****.**';
     $new_user_id = wp_insert_user(array('user_login' => 'user1', 'user_email' => $email));
     $user = get_user_by('email', $email);
     $this->assertFalse(is_wp_error($user));
     $lists = go_mailchimp()->api()->lists('mc');
     $this->assertGreaterThan(0, count($lists));
     $merge_vars = go_mailchimp()->api()->list_merge_vars($list_id);
     $this->assertGreaterThan(0, count($merge_vars));
     $member = go_mailchimp()->api()->subscribe($user, $list_id);
     $this->assertTrue(is_array($member));
     $this->assertFalse(empty($member['euid']));
     $member = go_mailchimp()->api()->subscribed($user, $list_id);
     $this->assertTrue(is_array($member));
     $this->assertFalse(empty($member['euid']));
     $unsubscribed = go_mailchimp()->api()->unsubscribed($user, $list_id);
     $this->assertTrue(empty($unsubscribed));
     $member = go_mailchimp()->api()->member($user, $list_id);
     $this->assertTrue(is_array($member));
     $this->assertFalse(empty($member['id']));
     // update the email
     $result = go_mailchimp()->api()->update_email($user, $new_email);
     $this->assertTrue($result);
     // change it back. make sure the email address in the user is
     // consistent with what we just updated (to $new_email)
     $user->user_email = $new_email;
     $result = go_mailchimp()->api()->update_email($user, $email);
     $this->assertTrue($result);
     // make sure user's email is consistent with what was updated
     $user->user_email = $email;
     $result = go_mailchimp()->api()->unsubscribe($user, $list_id);
     $this->assertTrue($result['complete']);
 }
コード例 #3
0
 /**
  * sync some of $user's MailChimp subscriber info into our user meta.
  * the information include the user's MC web_id, member_rating, and
  * geo latitude/longitude.
  *
  * @param WP_User $user a user object
  * @param string $list_id id of the list user is on
  * @return bool TRUE if successful, FALSE if not
  */
 public function sync_subscriber_info($user, $list_id)
 {
     $saved_subscriber_info = get_user_meta($user->ID, go_mailchimp()->meta_key('subscriber_info'), TRUE);
     if (empty($saved_subscriber_info) && !is_array($saved_subscriber_info)) {
         $saved_subscriber_info = array();
     }
     $membership_info = $this->member($user, $list_id);
     if (empty($membership_info)) {
         // user is not subscribed to the list any more
         unset($saved_subscriber_info[$list_id]);
     } else {
         $saved_subscriber_info[$list_id] = array('web_id' => $membership_info['web_id'], 'member_rating' => $membership_info['member_rating']);
         // assume if geo->latitude is set then so is geo->longitude
         if (isset($membership_info['geo']['latitude'])) {
             $saved_subscriber_info[$list_id]['geo'] = array('lat' => $membership_info['geo']['latitude'], 'lon' => $membership_info['geo']['longitude']);
         }
         //END if
     }
     //END else
     return update_user_meta($user->ID, go_mailchimp()->meta_key('subscriber_info'), $saved_subscriber_info);
 }
コード例 #4
0
 /**
  * @param WP_User $user a user object
  * @return the MC member rating from $user's user meta, or '' if we
  *  don't have one.
  */
 public function get_subscriber_rating($user)
 {
     if (empty($user->ID)) {
         return '';
     }
     if (!($usermeta = get_user_meta($user->ID, go_mailchimp()->meta_key('subscriber_info'), TRUE))) {
         return '';
     }
     if (empty($usermeta)) {
         return '';
     }
     // in our set up the user is generally only subscribed to one list
     // so we just pick the rating from the first list in the user meta
     foreach ($usermeta as $list_info) {
         if (empty($list_info['member_rating'])) {
             continue;
         }
         return $list_info['member_rating'];
     }
     return '';
 }
コード例 #5
0
<?php

/**
 * Plugin Name: Gigaom MailChimp Synchronization Plugin
 * Plugin URI: http://gigaom.com/
 * Description: Custom plugin to to synchronize arbitrary data to MailChimp email service.
 * Version: 0.2
 * Author: Gigaom <*****@*****.**>
 * Author URI: http://gigaom.com/
 * License: All Rights Reserved.
 */
require_once __DIR__ . '/components/class-go-mailchimp.php';
go_mailchimp();