function check_my_calendar()
{
    global $wpdb, $initial_listjs, $initial_caljs, $initial_minijs, $initial_ajaxjs, $mc_version, $grid_template, $rss_template, $list_template, $mini_template, $single_template, $defaults;
    $mcdb = $wpdb;
    mc_if_needs_permissions();
    $current_version = get_option('mc_version') == '' ? get_option('my_calendar_version') : get_option('mc_version');
    // If current version matches, don't bother running this.
    if ($current_version == $mc_version) {
        return true;
    }
    // Lets see if this is first run and create a table if it is!
    // Assume this is not a new install until we prove otherwise
    $new_install = false;
    $my_calendar_exists = false;
    $upgrade_path = array();
    // Determine the calendar version
    $tables = $mcdb->get_results("show tables;");
    foreach ($tables as $table) {
        foreach ($table as $value) {
            if ($value == MY_CALENDAR_TABLE) {
                $my_calendar_exists = true;
                // check whether installed version matches most recent version, establish upgrade process.
            }
        }
    }
    if ($my_calendar_exists == true && $current_version == '') {
        // If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
        $current_version = '1.5.9';
    }
    if ($my_calendar_exists == false) {
        $new_install = true;
    } else {
        // for each release requiring an upgrade path, add a version compare.
        // Loop will run every relevant upgrade cycle.
        if (version_compare($current_version, "1.8.0", "<")) {
            $upgrade_path[] = "1.8.0";
        }
        if (version_compare($current_version, "1.9.0", "<")) {
            $upgrade_path[] = "1.9.0";
        }
        if (version_compare($current_version, "1.9.1", "<")) {
            $upgrade_path[] = "1.9.1";
        }
        if (version_compare($current_version, "1.9.3", "<")) {
            $upgrade_path[] = "1.9.3";
        }
        if (version_compare($current_version, "1.10.0", "<")) {
            $upgrade_path[] = "1.10.0";
        }
        if (version_compare($current_version, "1.10.7", "<")) {
            $upgrade_path[] = "1.10.7";
        }
        if (version_compare($current_version, "1.11.0", "<")) {
            $upgrade_path[] = "1.11.0";
        }
        if (version_compare($current_version, "1.11.1", "<")) {
            $upgrade_path[] = "1.11.1";
        }
        if (version_compare($current_version, "2.0.0", "<")) {
            $upgrade_path[] = "2.0.0";
        }
        if (version_compare($current_version, "2.0.4", "<")) {
            $upgrade_path[] = "2.0.4";
        }
        if (version_compare($current_version, "2.1.0", "<")) {
            $upgrade_path[] = "2.1.0";
        }
        if (version_compare($current_version, "2.2.0", "<")) {
            $upgrade_path[] = "2.2.0";
        }
        if (version_compare($current_version, "2.2.6", "<")) {
            $upgrade_path[] = "2.2.6";
        }
        if (version_compare($current_version, "2.2.10", "<")) {
            $upgrade_path[] = "2.2.10";
        }
        if (version_compare($current_version, "2.3.0", "<")) {
            $upgrade_path[] = "2.3.0";
        }
    }
    // having determined upgrade path, assign new version number
    update_option('mc_version', $mc_version);
    // Now we've determined what the current install is or isn't
    if ($new_install == true) {
        //add default settings
        mc_default_settings();
        $sql = "INSERT INTO " . MY_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_color='#ffffcc', category_icon='event.png'";
        $mcdb->query($sql);
    } else {
        // clear cache so updates are immediately available
        mc_delete_cache();
    }
    // switch for different upgrade paths
    foreach ($upgrade_path as $upgrade) {
        switch ($upgrade) {
            // only upgrade db on most recent version
            case '2.3.0':
                delete_option('mc_location_control');
                $user_data = get_option('mc_user_settings');
                $loc_type = get_option('mc_location_type') == '' ? 'event_state' : get_option('mc_location_type');
                $locations[$loc_type] = $user_data['my_calendar_location_default']['values'];
                add_option('mc_use_permalinks', false);
                delete_option('mc_modified_feeds');
                add_option('mc_location_controls', $locations);
                add_option('mc_location_access', array('1' => __('Accessible Entrance', 'my-calendar'), '2' => __('Accessible Parking Designated', 'my-calendar'), '3' => __('Accessible Restrooms', 'my-calendar'), '4' => __('Accessible Seating', 'my-calendar'), '5' => __('Accessible Transportation Available', 'my-calendar'), '6' => __('Wheelchair Accessible', 'my-calendar'), '7' => __('Courtesy Wheelchairs', 'my-calendar'), '8' => __('Bariatric Seating Available', 'my-calendar'), '9' => __('Elevator to all public areas', 'my-calendar'), '10' => __('Braille Signage', 'my-calendar'), '11' => __('Fragrance-Free Policy', 'my-calendar'), '12' => __('Other', 'my-calendar')));
                add_option('mc_event_access', array('1' => __('Audio Description', 'my-calendar'), '2' => __('ASL Interpretation', 'my-calendar'), '3' => __('ASL Interpretation with voicing', 'my-calendar'), '4' => __('Deaf-Blind ASL', 'my-calendar'), '5' => __('Real-time Captioning', 'my-calendar'), '6' => __('Scripted Captioning', 'my-calendar'), '7' => __('Assisted Listening Devices', 'my-calendar'), '8' => __('Tactile/Touch Tour', 'my-calendar'), '9' => __('Braille Playbill', 'my-calendar'), '10' => __('Large Print Playbill', 'my-calendar'), '11' => __('Sensory Friendly', 'my-calendar'), '12' => __('Other', 'my-calendar')));
                $mc_input_options = get_option('mc_input_options');
                $mc_input_options['event_access'] = 'on';
                update_option('mc_input_options', $mc_input_options);
                mc_upgrade_db();
                mc_transition_db();
                break;
            case '2.2.10':
                delete_option('mc_show_print');
                delete_option('mc_show_ical');
                delete_option('mc_show_rss');
                break;
            case '2.2.8':
                delete_option('mc_draggable');
                break;
            case '2.2.6':
                delete_option('mc_caching_enabled');
                // remove caching support via options. Filter only.
                break;
            case '2.2.0':
                add_option('mc_inverse_color', 'true');
                break;
            case '2.1.0':
                $templates = get_option('mc_templates');
                global $rss_template;
                $templates['rss'] = $rss_template;
                update_option('mc_templates', $templates);
                break;
            case '2.0.4':
                update_option('mc_ical_utc', 'true');
                break;
            case '2.0.0':
                mc_migrate_db();
                update_option('mc_db_version', '2.0.0');
                $mc_input = get_option('mc_input_options');
                if (!isset($mc_input['event_specials'])) {
                    $mc_input['event_specials'] = 'on';
                    update_option('mc_input_options', $mc_input);
                }
                break;
            case '1.11.1':
                add_option('mc_event_link', 'true');
                break;
            case '1.11.0':
                add_option('mc_convert', 'true');
                add_option('mc_process_shortcodes', 'false');
                $add = get_option('mc_can_manage_events');
                // yes, this is correct.
                $manage = get_option('mc_event_edit_perms');
                $approve = get_option('mc_event_approve_perms');
                mc_add_roles($add, $manage, $approve);
                delete_option('mc_can_manage_events');
                delete_option('mc_event_edit_perms');
                delete_option('mc_event_approve_perms');
                break;
            case '1.10.7':
                update_option('mc_multisite_show', 0);
                break;
            case '1.10.0':
                update_option('mc_week_caption', "The week's events");
                break;
            case '1.9.1':
                update_option('mc_widget_defaults', $defaults);
                break;
            case '1.9.0':
                delete_option('mc_show_heading');
                add_option('mc_time_format', get_option('time_format'));
                add_option('mc_display_jump', get_option('display_jump'));
                add_option('mc_display_author', get_option('display_author'));
                if (get_option('can_manage_events') != '') {
                    add_option('mc_can_manage_events', get_option('can_manage_events'));
                } else {
                    add_option('mc_can_manage_events', 'manage_options');
                }
                add_option('mc_ajaxjs', get_option('my_calendar_ajaxjs'));
                add_option('mc_caljs', get_option('my_calendar_caljs'));
                add_option('mc_css_file', get_option('my_calendar_css_file'));
                add_option('mc_date_format', get_option('my_calendar_date_format'));
                add_option('mc_hide_icons', get_option('my_calendar_hide_icons'));
                add_option('mc_listjs', get_option('my_calendar_listjs'));
                add_option('mc_minijs', get_option('my_calendar_minijs'));
                add_option('mc_notime_text', get_option('my_calendar_notime_text'));
                add_option('mc_show_address', get_option('my_calendar_show_address'));
                add_option('mc_show_css', get_option('my_caledar_show_css'));
                add_option('mc_show_heading', get_option('my_calendar_show_heading'));
                add_option('mc_show_js', get_option('my_calendar_show_js'));
                add_option('mc_show_map', get_option('my_calendar_show_map'));
                add_option('mc_show_months', get_option('my_calendar_show_months'));
                add_option('mc_templates', get_option('my_calendar_templates'));
                add_option('mc_use_styles', get_option('my_calendar_use_styles'));
                add_option('mc_version', get_option('my_calendar_version'));
                add_option('mc_widget_defaults', get_option('my_calendar_widget_defaults'));
                add_option('mc_week_format', "M j, 'y");
                add_option('mc_calendar_javascript', get_option('calendar_javascript'));
                add_option('mc_list_javascript', get_option('list_javascript'));
                add_option('mc_mini_javascript', get_option('mini_javascript'));
                add_option('mc_ajax_javascript', get_option('ajax_javascript'));
                delete_option('ajax_javascript');
                delete_option('mini_javascript');
                delete_option('calendar_javascript');
                delete_option('list_javascript');
                delete_option('display_jump');
                delete_option('display_author');
                delete_option('can_manage_events');
                delete_option('my_calendar_week_format');
                delete_option('my_calendar_ajaxjs');
                delete_option('my_calendar_caljs');
                delete_option('my_calendar_css_file');
                delete_option('my_calendar_date_format');
                delete_option('my_calendar_hide_icons');
                delete_option('my_calendar_listjs');
                delete_option('my_calendar_minijs');
                delete_option('my_calendar_notime_text');
                delete_option('my_calendar_show_address');
                delete_option('my_calendar_show_css');
                delete_option('my_calendar_show_heading');
                delete_option('my_calendar_show_js');
                delete_option('my_calendar_show_map');
                delete_option('my_calendar_show_months');
                delete_option('my_calendar_templates');
                delete_option('my_calendar_use_styles');
                delete_option('my_calendar_version');
                delete_option('my_calendar_widget_defaults');
                add_option('mc_location_control', '');
                add_site_option('mc_multisite', '0');
                add_option('mc_templates', array('title' => '{title}', 'link' => '{title}', 'label' => '{title}', 'mini' => $mini_template, 'grid' => $grid_template, 'list' => $list_template, 'details' => $single_template));
                $mc_input = get_option('mc_input_options');
                $mc_input['event_image'] = 'on';
                update_option('mc_input_options', $mc_input);
                mc_upgrade_db();
                update_option('mc_db_version', '1.9.0');
            case '1.8.0':
                $mc_input = get_option('mc_input_options');
                add_option('mc_show_weekends', 'true');
                add_option('mc_uri', '');
                delete_option('my_calendar_stored_styles');
                break;
            default:
                break;
        }
    }
    /* 
    if the user has fully uninstalled the plugin but kept the database of events, this will restore default 
    settings and upgrade db if needed.
    */
    if (get_option('mc_uninstalled') == 'true') {
        mc_default_settings();
        update_option('mc_db_version', $mc_version);
        delete_option('mc_uninstalled');
    }
}
function check_my_calendar()
{
    global $wpdb, $mc_version;
    $mcdb = $wpdb;
    mc_if_needs_permissions();
    $current_version = get_option('mc_version') == '' ? get_option('my_calendar_version') : get_option('mc_version');
    if (version_compare($current_version, '2.3.12', '>=')) {
        // if current is a version higher than 2.3.11, they've already seen this notice and handled it.
        update_option('mc_update_notice', 1);
    }
    // If current version matches, don't bother running this.
    if ($current_version == $mc_version) {
        return true;
    }
    // Assume this is not a new install until we prove otherwise
    $new_install = false;
    $upgrade_path = array();
    if (my_calendar_exists() && $current_version == '') {
        // If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
        $current_version = '1.10.7';
    }
    if (!my_calendar_exists()) {
        $new_install = true;
    } else {
        // for each release requiring an upgrade path, add a version compare.
        // Loop will run every relevant upgrade cycle.
        $valid_upgrades = array('1.11.0', '1.11.1', '2.0.0', '2.0.4', '2.1.0', '2.2.0', '2.2.6', '2.2.10', '2.3.0', '2.3.11', '2.3.15', '2.4.4');
        foreach ($valid_upgrades as $upgrade) {
            if (version_compare($current_version, $upgrade, "<")) {
                $upgrade_path[] = $upgrade;
            }
        }
    }
    // having determined upgrade path, assign new version number
    update_option('mc_version', $mc_version);
    // Now we've determined what the current install is or isn't
    if ($new_install == true) {
        //add default settings
        mc_default_settings();
        $sql = "INSERT INTO " . MY_CALENDAR_CATEGORIES_TABLE . " SET category_id=1, category_name='General', category_color='#ffffcc', category_icon='event.png'";
        $mcdb->query($sql);
    } else {
        // clear cache so updates are immediately available
        mc_delete_cache();
    }
    mc_do_upgrades($upgrade_path);
    /*
    if the user has fully uninstalled the plugin but kept the database of events, this will restore default 
    settings and upgrade db if needed.
    */
    if (get_option('mc_uninstalled') == 'true') {
        mc_default_settings();
        update_option('mc_db_version', $mc_version);
        delete_option('mc_uninstalled');
    }
}