function wptreehouse_badges_options_page()
{
    if (!current_user_can('manage_options')) {
        wp_die('You do not have the correct permissions to view this page.');
    }
    global $plugin_url;
    global $options;
    if (isset($_POST['wptreehouse_form_submitted'])) {
        $hidden_field = esc_html($_POST['wptreehouse_form_submitted']);
        if ($hidden_field == 'Y') {
            $wptreehouse_username = esc_html($_POST['wptreehouse_username']);
            $wptreehouse_profile = wptreehouse_badges_get_profile($wptreehouse_username);
            $options['wptreehouse_username'] = $wptreehouse_username;
            $options['wptreehouse_profile'] = $wptreehouse_profile;
            $options['last_updated'] = time();
            update_option('wptreehouse_badges', $options);
        }
    }
    $options = get_option('wptreehouse_badges');
    if ($options != '') {
        $wptreehouse_username = $options['wptreehouse_username'];
        $wptreehouse_profile = $options['wptreehouse_profile'];
    }
    require 'inc/options-page-wrapper.php';
}
function wptreehouse_badges_refresh_profile()
{
    $options = get_option('wptreehouse_badges');
    $last_updated = $options['last_updated'];
    $current_time = time();
    $update_difference = $current_time - $last_updated;
    if ($update_difference > 86400) {
        $wptreehouse_username = $options['wptreehouse_username'];
        $options['wptreehouse_profile'] = wptreehouse_badges_get_profile($wptreehouse_username);
        $options['last_updated'] = time();
        update_option('wptreehouse_badges', $options);
    }
    die;
}
function wptreehouse_badges_refresh_profile()
{
    $options = get_option('wptreehouse_badges');
    //get the option to get the last update time
    $last_updated = $options['last_updated'];
    $current_time = time();
    $update_difference = $current_time - $last_updated;
    if ($update_difference > 86400) {
        // one day = 86400 seconds
        $wptreehouse_username = $options['wptreehouse_username'];
        $options['profile'] = wptreehouse_badges_get_profile($wptreehouse_username);
        $options['last_updated'] = time();
        update_option('wptreehouse_badges', $options);
        // update db
    }
    die;
    /* To tell Ajax that the function is completed */
}