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 render_meta_box()
 {
     $post = get_post();
     $settings = get_option('mailchimp_settings');
     $web_id = get_post_meta($post->ID, 'mailchimp_web_id', true);
     $mc_api_key_parts = explode('-', $settings['mailchimp_api_key']);
     $mc_api_endpoint = $mc_api_key_parts[1];
     $context = array('post' => $post, 'mc_api_endpoint' => $mc_api_endpoint, 'web_id' => $web_id);
     mailchimp_tools_render_template('campaign-preview.php', $context);
 }
 public function render_meta_box()
 {
     $post = get_post();
     $settings = get_option('mailchimp_settings');
     $existing = mailchimp_tools_get_existing_campaign_data_for_post($post, false);
     $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;
         }
     }
     $web_id = get_post_meta($post->ID, 'mailchimp_web_id', true);
     $mc_api_key_parts = explode('-', $settings['mailchimp_api_key']);
     $mc_api_endpoint = $mc_api_key_parts[1];
     $post_type_obj = get_post_type_object($this->post_type);
     $settings_key = $post_type_obj->name . '_mailchimp_settings';
     $saved_settings = get_option($settings_key, false);
     /**
      * Try to get existing group and subgroup data.
      *
      * Do this here instead of in the campaign-edit.php template
      * because it's fairly complex to parse the necessary info
      * from $existing data.
      */
     if (!empty($existing['segment_opts'])) {
         $existing_seg_opts = $existing['segment_opts'];
         if (isset($existing_seg_opts['conditions'])) {
             $conditions = $existing_seg_opts['conditions'][0];
             $saved_group_id = str_replace('interests-', '', $conditions['field']);
             $saved_subgroup_bit = $conditions['value'][0];
             $saved_group_settings = array('group' => array('saved_group_id' => $saved_group_id), 'subgroup' => array('saved_subgroup_bit' => $saved_subgroup_bit));
             /**
              * Use existing values for groups and subgroups if they were preset in $existing data
              */
             if (isset($saved_settings['segment'])) {
                 unset($saved_settings['segment']);
             }
             $saved_settings = wp_parse_args($saved_group_settings, $saved_settings);
         }
     }
     $context = array('lists' => $lists, 'segments' => $segments, 'groups' => $groups, 'templates' => $this->api->templates->getList(array('gallery' => false, 'base' => false), array('include_drag_and_drop' => true)), 'existing' => $existing, 'mc_api_endpoint' => $mc_api_endpoint, 'web_id' => $web_id, 'saved_settings' => $saved_settings);
     mailchimp_tools_render_template('campaign-edit.php', $context);
 }
 function render_settings_page()
 {
     mailchimp_tools_render_template('settings.php');
 }