コード例 #1
0
function mc_plugin_activated()
{
    flush_rewrite_rules();
    if (my_calendar_exists()) {
        mc_upgrade_db();
    }
    check_my_calendar();
}
コード例 #2
0
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');
    }
}