function test_missing_apikey()
 {
     $apikey = 'asdf';
     $api = new MailChimp_API($apikey);
     $key = mailchimpSF_verify_key($api);
     $this->assertTrue(is_wp_error($key));
 }
示例#2
0
function mailchimpSF_migrate_sopresto()
{
    $sopresto = get_option('mc_sopresto_secret_key');
    if (!$sopresto) {
        return;
    }
    // Talk to Sopresto, make exchange, delete old sopresto things.
    $body = array('public_key' => get_option('mc_sopresto_public_key'), 'hash' => sha1(get_option('mc_sopresto_public_key') . get_option('mc_sopresto_secret_key')));
    $url = 'https://sopresto.socialize-this.com/mailchimp/exchange';
    $args = array('method' => 'POST', 'timeout' => 500, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'MailChimp WordPress Plugin/' . get_bloginfo('url'), 'body' => $body);
    //post to sopresto
    $key = wp_remote_post($url, $args);
    if (!is_wp_error($key) && $key['response']['code'] == 200) {
        $key = json_decode($key['body']);
        try {
            $api = new MailChimp_API($key->response);
        } catch (Exception $e) {
            $msg = "<strong class='mc_error_msg'>" . $e->getMessage() . "</strong>";
            mailchimpSF_global_msg($msg);
            return;
        }
        $verify = mailchimpSF_verify_key($api);
        //something went wrong with the key that we had
        if (is_wp_error($verify)) {
            return;
        }
        delete_option('mc_sopresto_public_key');
        delete_option('mc_sopresto_secret_key');
        delete_option('mc_sopresto_user');
        return;
    }
    // Nothing to do here.
    return;
}