Example #1
0
/**
 * Sees if the user changed the list, and updates options accordingly
 **/
function mailchimpSF_change_list_if_necessary($api_key)
{
    // Simple permission check before going through all this
    if (!current_user_can(MCSF_CAP_THRESHOLD)) {
        return;
    }
    $api = new mailchimpSF_MCAPI($api_key);
    //we *could* support paging, but few users have that many lists (and shouldn't)
    $lists = $api->lists(array(), 0, 100);
    $lists = $lists['data'];
    if (is_array($lists) && !empty($lists) && isset($_POST['mc_list_id'])) {
        /* If our incoming list ID (the one chosen in the select dropdown)
        		is in our array of lists, the set it to be the active list */
        foreach ($lists as $key => $list) {
            if ($list['id'] == $_POST['mc_list_id']) {
                $list_id = $_POST['mc_list_id'];
                $list_name = $list['name'];
                $list_key = $key;
            }
        }
        $orig_list = get_option('mc_list_id');
        if ($list_id != '') {
            update_option('mc_list_id', $list_id);
            update_option('mc_list_name', $list_name);
            update_option('mc_email_type_option', $lists[$list_key]['email_type_option']);
            // See if the user changed the list
            if ($orig_list != $list_id) {
                // The user changed the list, Reset the Form Defaults
                mailchimpSF_set_form_defaults($list_name);
            }
            //		email_type_option
            // Grab the merge vars and interest groups
            $mv = $api->listMergeVars($list_id);
            $igs = $api->listInterestGroupings($list_id);
            update_option('mc_merge_vars', $mv);
            foreach ($mv as $var) {
                $opt = 'mc_mv_' . $var['tag'];
                //turn them all on by default
                if ($orig_list != $list_id) {
                    update_option($opt, 'on');
                }
            }
            update_option('mc_interest_groups', $igs);
            if (is_array($igs)) {
                foreach ($igs as $var) {
                    $opt = 'mc_show_interest_groups_' . $var['id'];
                    //turn them all on by default
                    if ($orig_list != $list_id) {
                        update_option($opt, 'on');
                    }
                }
            }
            $igs_text = ' ';
            if (is_array($igs)) {
                $igs_text .= sprintf(__('and %s Sets of Interest Groups', 'mailchimp_i18n'), count($igs));
            }
            $msg = '<p class="success_msg">' . sprintf(__('Success! Loaded and saved the info for %d Merge Variables', 'mailchimp_i18n') . $igs_text, count($mv)) . ' ' . __('from your list') . ' "' . $list_name . '"<br/><br/>' . __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n') . '</p>';
            mailchimpSF_global_msg($msg);
        }
    }
}
Example #2
0
/**
 * Sees if the user changed the list, and updates options accordingly
 **/
function mailchimpSF_change_list_if_necessary()
{
    // Simple permission check before going through all this
    if (!current_user_can(MCSF_CAP_THRESHOLD)) {
        return;
    }
    $api = mailchimpSF_get_api();
    if (!$api) {
        return;
    }
    //we *could* support paging, but few users have that many lists (and shouldn't)
    $lists = $api->get('lists', 100, array('fields' => 'lists.id,lists.name,lists.email_type_option'));
    $lists = $lists['lists'];
    if (is_array($lists) && !empty($lists) && isset($_POST['mc_list_id'])) {
        /* If our incoming list ID (the one chosen in the select dropdown)
           is in our array of lists, the set it to be the active list */
        foreach ($lists as $key => $list) {
            if ($list['id'] == $_POST['mc_list_id']) {
                $list_id = $_POST['mc_list_id'];
                $list_name = $list['name'];
                $list_key = $key;
            }
        }
        $orig_list = get_option('mc_list_id');
        if ($list_id != '') {
            update_option('mc_list_id', $list_id);
            update_option('mc_list_name', $list_name);
            update_option('mc_email_type_option', $lists[$list_key]['email_type_option']);
            // See if the user changed the list
            $new_list = false;
            if ($orig_list != $list_id) {
                // The user changed the list, Reset the Form Defaults
                mailchimpSF_set_form_defaults($list_name);
                $new_list = true;
            }
            //      email_type_option
            // Grab the merge vars and interest groups
            $mv = mailchimpSF_get_merge_vars($list_id, $new_list);
            $igs = mailchimpSF_get_interest_categories($list_id, $new_list);
            $igs_text = ' ';
            if (is_array($igs)) {
                $igs_text .= sprintf(__('and %s Sets of Interest Groups', 'mailchimp_i18n'), count($igs));
            }
            $msg = '<p class="success_msg">' . sprintf(__('<b>Success!</b> Loaded and saved the info for %d Merge Variables', 'mailchimp_i18n') . $igs_text, count($mv)) . ' ' . __('from your list') . ' "' . $list_name . '"<br/><br/>' . __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n') . '</p>';
            mailchimpSF_global_msg($msg);
        }
    }
}