public function render_settings_page()
 {
     if (isset($_POST) && isset($_POST[$this->settings_key])) {
         $this->process_form($_POST[$this->settings_key]);
     }
     $this->api = mailchimp_tools_get_api_handle();
     $lists = $this->api->lists->getList();
     $segments = array();
     $groups = array();
     foreach ($lists['data'] as $list) {
         $list_segments = $this->api->lists->segments($list['id']);
         if (!empty($list_segments['saved'])) {
             $segments[$list['id']] = $list_segments['saved'];
         }
         try {
             $list_groups = $this->api->lists->interestGroupings($list['id']);
             if (!empty($list_groups)) {
                 $groups[$list['id']] = $list_groups;
             }
         } catch (Mailchimp_List_InvalidOption $e) {
             continue;
         }
     }
     $context = array('lists' => $lists, 'segments' => $segments, 'groups' => $groups, 'templates' => $this->api->templates->getList(array('gallery' => false, 'base' => false), array('include_drag_and_drop' => true)), 'post_type_obj' => $this->post_type_obj, 'settings_key' => $this->settings_key, 'saved_settings' => get_option($this->settings_key, false));
     mailchimp_tools_render_template('post-type-settings.php', $context);
 }
 public function __construct($post_type = 'post')
 {
     $this->post_type = $post_type;
     $this->api = mailchimp_tools_get_api_handle();
     add_action('admin_menu', array($this, 'add_meta_box'));
     add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
     add_action('save_post_' . $this->post_type, array($this, 'process_form'), 9999, 2);
 }
 /**
  * Get source code for a MailChimp template_id
  *
  * @since 0.0.1
  */
 function mailchimp_tools_get_template_source($template_id = null)
 {
     if (!empty($template_id)) {
         $transient_key = 'mailchimp_tools_template_source_' . $template_id;
         $cached = get_transient($transient_key);
         if ($cached !== false) {
             return $cached;
         }
         $api = mailchimp_tools_get_api_handle();
         if (!empty($api)) {
             $template_details = $api->templates->info($template_id);
             $ret = $template_details['source'];
             set_transient($transient_key, $ret, defined('WP_DEBUG') && WP_DEBUG ? 60 : 60 * 60);
             return $ret;
         }
     }
     return null;
 }