/** * Sets the API Key to whatever value was passed to this func * * @return array of vars **/ function mailchimpSF_set_api_key($api_key = '') { $delete_setup = false; $api = new mailchimpSF_MCAPI($api_key); $api->ping(); if (empty($api->errorCode)) { $msg = "<p class='success_msg'>" . esc_html(__("Success! We were able to verify your API Key! Let's continue, shall we?", 'mailchimp_i18n')) . "</p>"; update_option('mc_apikey', $api_key); $req = $api->getAccountDetails(); update_option('mc_username', $req['username']); update_option('mc_user_id', $req['user_id']); $cur_list_id = get_option('mc_list_id'); if (!empty($cur_list_id)) { //we *could* support paging, but few users have that many lists (and shouldn't) $lists = $api->lists(array(), 0, 100); $lists = $lists['data']; //but don't delete if the list still exists... $delete_setup = true; foreach ($lists as $list) { if ($list['id'] == $cur_list_id) { $list_id = isset($_POST['mc_list_id']) ? $_POST['mc_list_id'] : ''; $delete_setup = false; } } } } else { $msg = "<p class='error_msg'>" . esc_html(__('Uh-oh, we were unable to verify your API Key. Please check them and try again!', 'mailchimp_i18n')) . "<br/>"; $msg .= __('The server said:', 'mailchimp_i18n') . "<em>" . esc_html($api->errorMessage) . "</em></p>"; $username = get_option('mc_username'); if (empty($username)) { $delete_setup = true; } } // Set a global message mailchimpSF_global_msg($msg); // If we need to delete our setup, do it if ($delete_setup) { mailchimpSF_delete_setup(); } }
function test_delete_everything() { $fname = array('tag' => 'FNAME', 'name' => 'First Name', 'type' => 'text', 'required' => 'Y'); $ig = array('id' => '123'); $igs[] = $ig; update_option('mc_list_id', '123'); update_option('mc_list_name', 'asdf'); update_option('mc_interest_groups', $igs); update_option('mc_merge_vars', array($fname)); update_option('mc_show_interest_groups_123', 'on'); update_option('mc_mv_FNAME', $fname); $this->assertTrue(is_string(get_option('mc_list_id'))); $this->assertTrue(is_string(get_option('mc_list_name'))); $this->assertTrue(is_string(get_option('mc_show_interest_groups_123'))); $this->assertTrue(is_array(get_option('mc_mv_FNAME'))); mailchimpSF_delete_setup(); $this->assertFalse(get_option('mc_list_id')); $this->assertFalse(get_option('mc_list_name')); $this->assertFalse(get_option('mc_show_interest_groups_123')); $this->assertFalse(get_option('mc_mv_FNAME')); }