function wp_sh_check_db_ver()
{
    global $wp_sh_db_ver, $wp_sh_setting_opt;
    $current_checkver_stamp = get_option('wp_sh_checkver_stamp');
    if (!$current_checkver_stamp || version_compare($current_checkver_stamp, $wp_sh_db_ver, "!=")) {
        $updated_count = 0;
        $migration_count = 0;
        // Register languages when new installation, updated from ver 1.2.3 or older
        if (!$current_checkver_stamp || version_compare($current_checkver_stamp, "1.3", "<")) {
            wp_sh_language_array();
            $updated_count = $updated_count + 1;
        }
        // Register settings when new installation, updated from ver 1.5 or older
        if (!is_array($wp_sh_setting_opt)) {
            wp_sh_setting_array();
            $updated_count = $updated_count + 1;
        }
        // Setting data migration when updated from ver.1.5 or older
        if (!$current_checkver_stamp || version_compare($current_checkver_stamp, "1.5", "<=")) {
            if (get_option('wp_sh_theme')) {
                include_once 'data-migration.php';
                $migration_count = $updated_count + 1;
                // Delete un-used options before ver.1.5
                include_once 'del-old-options.php';
            }
        }
        // If possible, update to current default values
        if (!$current_checkver_stamp || version_compare($current_checkver_stamp, "1.3.9", "<")) {
            // This option is available since ver 1.0 and updated in ver. 1.3.9
            if (get_option('wp_sh_class_name') == '') {
                update_option('wp_sh_class_name', wp_sh_default_setting_value('class'));
                $updated_count = $updated_count + 1;
            }
        }
        if (version_compare($current_checkver_stamp, "1.3", ">=") && version_compare($current_checkver_stamp, "1.5", "<")) {
            // This option is available since ver. 1.3.5 and updated in ver. 1.5
            if ($wp_sh_setting_opt['addl_style_enable'] == 0) {
                update_option('wp_sh_addl_style', wp_sh_default_setting_value('style'));
                $updated_count = $updated_count + 1;
            }
        }
        if (version_compare($current_checkver_stamp, "1.5", "==")) {
            // This option is available since ver. 1.5 and updated in ver. 1.5.5
            if ($wp_sh_setting_opt['comment_hl_description_before_enable'] == 0) {
                update_option('wp_sh_comment_hl_description_before', wp_sh_default_setting_value('comment_desc'));
                $updated_count = $updated_count + 1;
            }
            if ($wp_sh_setting_opt['comment_hl_stylesheet_enable'] == 0) {
                update_option('wp_sh_comment_hl_stylesheet', wp_sh_default_setting_value('comment_style'));
                $updated_count = $updated_count + 1;
            }
        }
        // Add new setting options when updated from ver.1.5.8 or older
        if ($current_checkver_stamp && version_compare($current_checkver_stamp, "1.5.5", "<=")) {
            if (version_compare(get_bloginfo('version'), "3.0.6", "<=")) {
                $wp_sh_setting_opt['quicktag'] = 0;
            } else {
                $wp_sh_setting_opt['quicktag'] = 1;
            }
            update_option('wp_sh_setting_opt', $wp_sh_setting_opt);
            $updated_count = $updated_count + 1;
        }
        // Add new setting options when updated from ver.1.6 or older
        if ($current_checkver_stamp && version_compare($current_checkver_stamp, "1.6", "<=")) {
            $wp_sh_setting_opt['quicktag_jquery'] = 0;
            // Correct a typo
            if ($wp_sh_setting_opt['theme'] == "Randam") {
                $wp_sh_setting_opt['theme'] = "Random";
            }
            update_option('wp_sh_setting_opt', $wp_sh_setting_opt);
            $updated_count = $updated_count + 1;
        }
        // Add new setting options when updated from ver.1.6.5 or older
        if ($current_checkver_stamp && version_compare($current_checkver_stamp, "1.6.5", "<=")) {
            $wp_sh_setting_opt['quick_code'] = "true";
            update_option('wp_sh_setting_opt', $wp_sh_setting_opt);
            $updated_count = $updated_count + 1;
        }
        // Add new setting options when updated from ver.1.6.7 or older
        if ($current_checkver_stamp && version_compare($current_checkver_stamp, "1.6.7", "<=")) {
            $wp_sh_setting_opt['editor_shorcode'] = 0;
            $wp_sh_setting_opt['editor_no_unfiltered_html'] = 0;
            $wp_sh_setting_opt['comment_hl_bt_tag'] = "pre";
            $wp_sh_setting_opt['comment_hl_bt_shorcode'] = 0;
            if (version_compare(get_bloginfo('version'), "3.2.1", "<=")) {
                $wp_sh_setting_opt['comment_quicktag'] = 0;
            } else {
                $wp_sh_setting_opt['comment_quicktag'] = 1;
            }
            $wp_sh_setting_opt['comment_jquery'] = 0;
            $wp_sh_setting_opt['wiget_tag'] = "pre";
            $wp_sh_setting_opt['wiget_shorcode'] = 0;
            $wp_sh_setting_opt['highlight_bbpress'] = 0;
            $wp_sh_setting_opt['bbpress_hl_bt_enable'] = 0;
            $wp_sh_setting_opt['bbpress_hl_bt_tag'] = "pre";
            $wp_sh_setting_opt['bbpress_hl_bt_shorcode'] = 0;
            $wp_sh_setting_opt['bbpress_hl_bt_guest'] = 0;
            $wp_sh_setting_opt['bbpress_hl_description_before_enable'] = 0;
            $wp_sh_setting_opt['bbpress_hl_stylesheet_enable'] = 0;
            update_option('wp_sh_setting_opt', $wp_sh_setting_opt);
            add_option('wp_sh_bbpress_hl_description_before', wp_sh_default_setting_value('bbp_desc'));
            add_option('wp_sh_bbpress_hl_stylesheet', wp_sh_default_setting_value('bbp_style'));
            $updated_count = $updated_count + 1;
        }
        update_option('wp_sh_checkver_stamp', $wp_sh_db_ver);
        // Stamp for showing messages
        if ($updated_count != 0 && $migration_count == 0) {
            update_option('wp_sh_updated', 'true');
        } elseif ($migration_count != 0) {
            update_option('wp_sh_updated', 'migration');
        }
    }
}
function wp_sh_reset_setting()
{
    global $wp_sh_db_ver;
    // Remove all settings from DB
    include_once 'uninstall.php';
    // Register default settings
    wp_sh_language_array();
    wp_sh_setting_array();
    add_option('wp_sh_checkver_stamp', $wp_sh_db_ver);
    // Message for admin
    echo "<div id='setting-error-settings_updated' class='updated fade'><p><strong>" . __("All settings were reset. Please <a href=\"options-general.php?page=wp-syntaxhighlighter-options\">reload the page</a>.", "wp_sh") . "</strong></p></div>";
}