/** * Get an array of list_id => number of subscribers * * @return array */ public function get_subscriber_counts() { // get from transient $list_counts = get_transient('mc4wp_list_counts'); if (is_array($list_counts)) { return $list_counts; } // transient not valid, fetch from API try { $lists = $this->api->get_lists(array('count' => 100, 'fields' => 'lists.id,lists.stats')); } catch (MC4WP_API_Exception $e) { return array(); } $list_counts = array(); // we got a valid response foreach ($lists as $list) { $list_counts["{$list->id}"] = $list->stats->member_count; } $seconds = 3600; /** * Filters the cache time for MailChimp lists configuration, in seconds. Defaults to 3600 seconds (1 hour). * * @since 2.0 * @param int $seconds */ $transient_lifetime = (int) apply_filters('mc4wp_lists_count_cache_time', $seconds); set_transient('mc4wp_list_counts', $list_counts, $transient_lifetime); // bail return $list_counts; }
} // in case the migration is _very_ late to the party if (!class_exists('MC4WP_API_v3')) { return; } $options = get_option('mc4wp', array()); if (empty($options['api_key'])) { return; } // get current state from transient $lists = get_transient('mc4wp_mailchimp_lists_fallback'); if (empty($lists)) { return; } @set_time_limit(600); $api_v3 = new MC4WP_API_v3($options['api_key']); $map = array(); foreach ($lists as $list) { // cast to stdClass because of missing classes $list = (object) (array) $list; // no groupings? easy! if (empty($list->groupings)) { continue; } // fetch (new) interest categories for this list try { $interest_categories = $api_v3->get_list_interest_categories($list->id); } catch (MC4WP_API_Exception $e) { continue; } foreach ($interest_categories as $interest_category) {